home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / quintus / quintus0.lha / work / hyper_2.06.2 < prev    next >
Text File  |  1992-04-03  |  67KB  |  1,957 lines

  1. %%% HYPER MATCHING
  2. %%% version 2.00.7 (based on hyper_19.3)
  3. %%%   moved term rewriting to hypermatching
  4. %%% version 2.00.9
  5. %%%   added bound on term rewriting
  6. %%% version 2.01.0
  7. %%%   checked clause priority after each hyper-link
  8. %%% version 2.01.3
  9. %%%   moved generation of rewrite rules to hyper-linking
  10. %%%   fixed bug when rewriting hyper-links from a unit nucleus
  11. %%%   added code to orient equations
  12. %%% version 2.01.4
  13. %%%   modified rewriting of equations according to David Plaisted's method
  14. %%% version 2.01.6
  15. %%%   sorted electrons by term size
  16. %%% version 2.01.8
  17. %%%   recomputed variable list when rewriting hyper-link
  18. %%% version 2.02.1
  19. %%%   added partial hyper-links to priority structure
  20. %%%   asserted over_priohm if priority exceeded during rewriting or
  21. %%%     hyper-linking
  22. %%%   fixed bug which counted hyper-links rejected after rewriting as good
  23. %%%   added partial rewrite count
  24. %%% version 2.02.3
  25. %%%   deleted pulled out form of clauses whose priority is too large
  26. %%% version 2.02.4
  27. %%%   fixed bugs when updating priority structure with partial hyper-link
  28. %%% version 2.02.5
  29. %%%   fixed bug when updating priority structure with partial hyper-link
  30. %%% version 2.02.7
  31. %%%   modified code so clauses corresponding to rewrite rules are not deleted
  32. %%% version 2.02.8
  33. %%%   deleted rewrite rules when the priority of the lhs exceeds the priority
  34. %%%     bound
  35. %%% version 2.02.9
  36. %%%   performed time overflow check after rejecting hyper-link due to priority
  37. %%% version 2.03.0
  38. %%%   moved rewrite rule simplification to hyper-linking
  39. %%%   performed time overflow check after rejecting hyper-link due to relevance
  40. %%%   counted hyper-links rejected due to relevance as rejected
  41. %%% version 2.03.1
  42. %%%   added early unit subsumption by X=X test
  43. %%% version 2.03.2
  44. %%%   modified rewriting of equations so that equations are fully rewritten
  45. %%% version 2.03.3
  46. %%%   strengthened early unit subsumption test so that partial hyper-links
  47. %%%     having all linked negative equations linked with X=X are tested
  48. %%%     using restricted rewrite
  49. %%%   fixed bug in the determination of linked and unlinked literals in partial
  50. %%%     hyper-links
  51. %%%   removed unit nucleus optimization from proc_C as modification for
  52. %%%     rewriting is more costly than normal processing
  53. %%%   removed unit nucleus optimization from calculate_new_size,
  54. %%%     calculate_priority_HM, make_varstail as it doesn't work with rewriting
  55. %%%   removed ground hyper-link optimization from calculate_new_size and
  56. %%%     calculate_priority_HM as it doesn't work with rewriting
  57. %%% version 2.03.4
  58. %%%   incorporated changes made to clin V1 between 7/31/90 and 10/18/90 which
  59. %%%     are visible externally -- changes to comments, predicate names, and
  60. %%%     variable names are not incorporated
  61. %%%   printed deleting rewrite rule message only when outrwr set
  62. %%%   modified deleting rewrite rule message
  63. %%%   performed early unit subsumption test only when "equality_transform"
  64. %%% version 2.03.5
  65. %%%   removed counters
  66. %%%   restored unit nucleus and ground nucleus optimizations to
  67. %%%     calculate_new_size, calculate_priority_HM, make_varstail, and
  68. %%%     proc_C when no rewrite rules
  69. %%% version 2.03.6
  70. %%%   don't recalculate variable list after rewriting hyper-link as variable
  71. %%%     list is for nucleus
  72. %%% version 2.03.9
  73. %%%   don't update priority structure in early priority test
  74. %%% version 2.04.0
  75. %%%   performed unit deletion in early priority test
  76. %%%   logically erased nuclei while hyper-linking
  77. %%%   don't try to delete pulled out forms unless equality_transform set
  78. %%% version 2.04.3
  79. %%%   erased corresponding equation and pulled out form when simplifying
  80. %%%     rewrite rule
  81. %%%   fixed rmrwr_prio so it erased all rewrite rules whose lhs was larger
  82. %%%     than the priority bound
  83. %%%   updated priority structure when early priority test succeeds
  84. %%% version 2.04.4
  85. %%%   no longer pull out equations at the beginning of rounds
  86. %%% version 2.04.5
  87. %%%   added equality_transform_by_round flag
  88. %%%   added safe_early_priority_test flag
  89. %%%   added early_unit_subsumption flag
  90. %%%   added early tautology test
  91. %%%   removed rewriting from hyper-linking
  92. %%%   removed the generation of rewrite rules from hyper-linking
  93. %%% version 2.04.6
  94. %%%   added fixed_priority
  95. %%%   removed unnecessary checks for rewrite rules now that rewriting is no
  96. %%%     longer done in hyper-linking
  97. %%% version 2.04.7
  98. %%%   added limited rewrite to hyper-linking
  99. %%%   moved code to erase clause corresponding to rewrite rule from
  100. %%%     erase_rewrite_rule to rmrwr_prio
  101. %%% version 2.04.8
  102. %%%   fixed bug in early priority test which updated priority for partial
  103. %%%     instances which passed test instead of those which failed
  104. %%%   rewrote partial instance before early tautology test and early priority
  105. %%%     test
  106. %%% version 2.05.0
  107. %%%   improved the efficiency of the unit deletion in early priority test
  108. %%%   checked for duplicate partial instances
  109. %%%   rejected a partial instance which is an instance of a previous partial
  110. %%%     instance only when delete_all_instances is set
  111. %%%   ordered early tests as early priority test, early tautology test,
  112. %%%     duplicate partial instance test, and early unit subsumption
  113. %%%   deleted a rewrite rule if its rhs priority is larger than the priority
  114. %%%     bound
  115. %%%   deleted a partial instance if its priority is larger than the priority
  116. %%%     bound
  117. %%%   rewrote literal before linking it
  118. %%%   erased partial instances for each nucleus
  119. %%% version 2.05.3
  120. %%%   added support for Quintus Prolog
  121. %%%   fixed bug when updating priority structure after early priority failure
  122. %%%   modified rmhm_prio to delete equations corresponding to rewrite rules
  123. %%%     if their priority exceeds priority bound
  124. %%%   modified rmhm_prio not to delete pulled out forms when deleting a clause
  125. %%%   modified update_priority_structure to delete partial instances whose
  126. %%%     priority exceeds the priority bound
  127. %%%   updated priority structure with priority from partial instances not
  128. %%%     rejected by early priority test
  129. %%%   don't perform early tests on unlinked partial instances
  130. %%%   performed early unit subsumption test in get_hm_nucleus
  131. %%%   performed partial instance check in get_hm_nucleus
  132. %%%   no longer erased partial instances for each nucleus
  133. %%%   fixed electron instance check so it doesn't erase and assert lit_G while
  134. %%%     backtracking over lit_G
  135. %%% version 2.05.5
  136. %%%   added equational rewriting
  137. %%%   don't erase clauses when erasing large rewrite rules
  138. %%% version 2.05.6
  139. %%%   changed early unit subsumption to equality early unit subsumption
  140. %%%   added new early unit subsumption
  141. %%% version 2.05.7
  142. %%%   ehanced equality early unit subsumption test
  143. %%%   don't hyper-link unit nuclei
  144. %%% version 2.06.0
  145. %%%   added bug fixes from Shie-Jue
  146. %%%   added early check for unit conflict
  147. %%% version 2.06.1
  148. %%%   fixed bug in hm_literal which sometimes erronously failed to link
  149. %%%   fully sort nuclei before hyper-linking
  150. %%% version 2.06.2
  151. %%%   added fast_priority_update
  152. %%%   added duplicate_partial_instance_test
  153. %%%   check for unit conflict in hyper when sliding priority not specified
  154. %%%
  155. %%% hm_round hyper-matches the input clauses one round,
  156. %%% and generates new clauses. These new clauses are not variant 
  157. %%% to each other, nor variant to any clause in the input clauses.
  158. %%%
  159. %%% The strategy here is bottom-up strategy.
  160. %%% The idea is we find the first mate for the first literal, then 
  161. %%% find the first mate for the second literal, etc., until we find
  162. %%% the first mate for the last literal. Then we backtrack for the
  163. %%% last literal and find the second mate for the last literal, and
  164. %%% then the last mate for the last literal. Then we backtrack to find
  165. %%% the second mate for the next to last literal, and so forth, until
  166. %%% we find the last mate for the first literal.
  167. %%%
  168. %%% The disadvantage for this is we can't delete duplicates for the
  169. %%% intermediate hyper-matches. The advanteage for this strategy is that 
  170. %%% we don't need to store the intermediate hyper-matches.
  171. %%%
  172. %%% Some comments:
  173. %%%    (A)
  174. %%%    supported clause not implies new clause
  175. %%%    new clause implies supported clause in some strategy
  176. %%%    distance 0 clause implies supported clause
  177. %%%    distance 0 clause not implies new clause
  178. %%%    supported clause not implies distance 0 clause
  179. %%%    distance 0 clause iff supported input clause or its hyper-matches
  180. %%%    distance 0 clause and its hyper-matches implies supported clause
  181. %%%    (B)    
  182. %%%    The calculation of distance should be done properly:
  183. %%%    1. no same literal connects two edges in a path
  184. %%%        This requirement is not enforced for user support.
  185. %%%    2. calculate three distances at the same time
  186. %%%        a. maximum forward distance for negative literals.
  187. %%%        b. maximum backward distance for positive literals.
  188. %%%        c. minimum user distance for user supported literals.
  189. %%%
  190. %%% Checking the number of distinct variales in a clause:
  191. %%%     If a hyper-match has more distichnct variables than constants in the
  192. %%%       constant list, then print out error message, ignore the hyper-
  193. %%%       match, and go ahead the proof.
  194. %%%
  195. %%%   We keep three kinds of clauses. sent_C is the nuclei. sent_T are the
  196. %%%   hyper-matches which are duplicates to sent_C. sent_HM are hyper-matches
  197. %%%   which are not duplicates to sent_C.
  198. %%%    1. take one sent_C.
  199. %%%    2. Check a hyper-match against sent_HM, sent_T, sent_C.
  200. %%%    3. If the hyper-match has no duplicates from neither source, then 
  201. %%%         it is asserted as sent_HM. Increase the hyper-match number 
  202. %%%        count.
  203. %%%    4. If the hyper-match has a duplicate in sent_HM:
  204. %%%       a. If the clause information of the hyper-match is contained in
  205. %%%        those of the duplicate, do nothing.
  206. %%%       b. If not, then retract the duplicate, and assert a clause sent_HM
  207. %%%        with updated clause information.
  208. %%%    5. If the hyper-match has a duplicate in sent_T:
  209. %%%       a. If the clause information of the hyper-match is contained in
  210. %%%               those of the duplicate, do nothing.  
  211. %%%          b. If not, then retract the duplicate, and assert a clause sent_T
  212. %%%               with updated clause information.
  213. %%%    6. If the hyper-match has a duplicate in sent_C, assert it as sent_T.
  214. %%%    7. do throw-away strategy on sent_C.
  215. %%%    8. Merge sent_T into sent_C and remove duplicates.
  216. %%%    9. rename sent_HM to sent_C.
  217. %%%
  218. %%% Since we use contradiction checking in the prover, otherwise it is not
  219. %%%    complete, the following facts hold:
  220. %%%    1. A nucelus has no unit mates in UR.
  221. %%%    2. A unit nucleus has no unit mates in U,B,and F.
  222. %%%
  223. %%% Unit deletion: If a nucleus literal has a mate from a unit clause, 
  224. %%%     then we won't record this literal in database with the instance.
  225. %%% Empty hyper-match detection: The hyper-matching stops whenever an
  226. %%%    empty hyper-match is generated.
  227. %%%
  228. %%% Time control: Before we hyper-match a nucleus, we check if the time
  229. %%%    is overflowed. If so, stop the hyper-matching and do the other
  230. %%%    stages with the hyper-matches obtained so far.
  231. %%%
  232. %%% Shorter nucleus first serve: In order to reduce the number of assertions
  233. %%%    and deletions with sliding priority, we starts with the shorter
  234. %%%     nuclei to do hyper-matching.
  235. %%%
  236. %%% Add an option, ground_hyper_match, to accept ground hyper matches.
  237. %%%    If ground_hyper_match is specified, then
  238. %%%        we don't throw away nucleus
  239. %%%        we don't accept non-ground hyper-matches.
  240. %%%
  241. %%% Don't count ground literals when considering literal bounds.
  242. %%%    We check this after duplicate checking.
  243. %%%
  244. %%% Match ground literals first.
  245. %%%
  246. %%% The order of match is determined by the number of non-ground literals
  247. %%%    in a nucleus, not the number of literals any more, since ground
  248. %%%    literals do not backtrack.
  249. %%%     So we change data structure to have a field recording the number
  250. %%%    of non-ground literals in a clause.
  251. %%%
  252.  
  253.      hm_round :- 
  254.          not(not(hm_round_fail)),
  255.     !.
  256.  
  257.      hm_round_fail :-
  258.     cputime(TT1),
  259.     hm_round0,
  260.     cputime(TT2),
  261.     TT3 is TT2 - TT1,
  262.     update_hypermatch_time(TT3),
  263.     write_line(5,'Hyper-linking(s): ',TT3),
  264.     !.
  265.  
  266. %%% We record the time spent in hyper-matching just done. This time is
  267. %%% used for controlling the following small proof checking.
  268.      update_hypermatch_time(TT3) :-
  269.     abolish(last_hypermatch_time,1),
  270.     assert(last_hypermatch_time(TT3)).
  271.  
  272. %%% 1. calculate the non-duplicate literal list.
  273. %%% 2. obtain two literal lists: one is the list of supported literals
  274. %%%    and the other one is the whole list itself.
  275. %%% 3. do hyper-matching one nucleus at a time.
  276. %%% 4. update the clauses in the database.
  277.      hm_round0 :-
  278.     set_counter(counter1,0),
  279.     set_counter(counter2,0),
  280.     set_counter(counter3,0),
  281.     set_counter(counter4,0),
  282.     litsall_hm,
  283.     supported_mates,
  284.     sort_lits,
  285.     print_litsall,
  286.     bagof1(RSLit,(US,LBYS,LSS,LRS)^clause(lit_S(US,LBYS,LSS,LRS),
  287.         true,RSLit),RSLists),
  288.     bagof1(RGLit,(UG,LBYG,LSG,LRG)^clause(lit_G(UG,LBYG,LSG,LRG),
  289.         true,RGLit),RGLists),
  290.         hm_round1(RSLists,RGLists),
  291.     physically_erase(sent_C),
  292.     abolish(lit_S,4),
  293.     abolish(lit_G,4),
  294.     abolish(part_inst,4),
  295.      not(not(update_sentC)),
  296.     counter(counter1,Counter1),
  297.     write_line(10,'Early tautology:                      ',Counter1),
  298.     counter(counter2,Counter2),
  299.     write_line(10,'Duplicate Partial Instances:          ',Counter2),
  300.     counter(counter3,Counter3),
  301.     write_line(10,'Early Unit Subsumption:               ',Counter3),
  302.     counter(counter4,Counter4),
  303.     write_line(10,'Equality Early Unit Subsumption:      ',Counter4),
  304.     !.
  305.  
  306. %%% sort the literals.
  307.      sort_lits :-
  308.     sort_lit_G,
  309.     sort_lit_S,
  310.     !.
  311.      sort_lit_G :-
  312.     bagof1([G1,G2,G3,G4],lit_G(G1,G2,G3,G4),GLits1),
  313.         abolish(lit_G,4),
  314.     sort_lit_G_1(GLits1,GLits2),
  315.     sort(GLits2,GLits3),
  316.     sort_lit_G_3(GLits3),
  317.     !.
  318.      sort_lit_G_1([],[]).
  319.      sort_lit_G_1([[G1,G2,G3,G4]|GLits1],[{S,Lg,[G1,G2,G3,G4]}|GLits2]) :-
  320.     G2=..[_,L,V1,V2,_],
  321.     not(not(sort_lit_G_2(L,V1,V2))),
  322.     retract(slG_temp1(S)),
  323.     retract(slG_temp2(Lg)),
  324.     !,
  325.     sort_lit_G_1(GLits1,GLits2).
  326.      sort_lit_G_2(L,V,V) :-
  327.     literal_size(L,S),
  328.     assert(slG_temp1(S)),
  329.     ground(L,Lg,_,_),
  330.     assert(slG_temp2(Lg)).
  331.      sort_lit_G_3([]).
  332.      sort_lit_G_3([{_,_,[G1,G2,G3,G4]}|GLits]) :-
  333.     assertz(lit_G(G1,G2,G3,G4)),
  334.     !,
  335.     sort_lit_G_3(GLits).
  336.      sort_lit_S :-
  337.     bagof1([S1,S2,S3,S4],lit_S(S1,S2,S3,S4),SLits1),
  338.         abolish(lit_S,4),
  339.     sort_lit_S_1(SLits1,SLits2),
  340.     sort(SLits2,SLits3),
  341.     sort_lit_S_3(SLits3),
  342.     !.
  343.      sort_lit_S_1([],[]).
  344.      sort_lit_S_1([[S1,S2,S3,S4]|SLits1],[{S,Lg,[S1,S2,S3,S4]}|SLits2]) :-
  345.     S2=..[_,L,V1,V2,_],
  346.     not(not(sort_lit_S_2(L,V1,V2))),
  347.     retract(slS_temp1(S)),
  348.     retract(slS_temp2(Lg)),
  349.     !,
  350.     sort_lit_S_1(SLits1,SLits2).
  351.      sort_lit_S_2(L,V,V) :-
  352.     literal_size(L,S),
  353.     assert(slS_temp1(S)),
  354.     ground(L,Lg,_,_),
  355.     assert(slS_temp2(Lg)).
  356.      sort_lit_S_3([]).
  357.      sort_lit_S_3([{_,_,[S1,S2,S3,S4]}|SLits]) :-
  358.     assertz(lit_S(S1,S2,S3,S4)),
  359.     !,
  360.     sort_lit_S_3(SLits).
  361.  
  362. %%% hyper-matching one clause each time.
  363. %%% starting with the smallest clauses
  364.      hm_round1(RSLists,RGLists) :-
  365.     get_hm_nucleus(C,RefNucl),
  366.     hm_clause(C,RefNucl,RSLists,RGLists),
  367.     check_hm_stop,
  368.     !.
  369.      hm_round1(_,_).
  370.  
  371. %%% Stop if an empty hyper-match is generated or time overflows.
  372.      check_hm_stop :-
  373.     prove_result(unsatisfiable), !.
  374.      check_hm_stop :-
  375.     is_time_overflow.
  376.  
  377. %%% get a nucleus in order of number of literals.
  378.      get_hm_nucleus(C,RefNucl) :-
  379.     bagof1([N,S,Cg]-Ref,get_hm_nucleus_1(N,S,Cg,Ref),Nuclei1),
  380.     keysort(Nuclei1,Nuclei2),
  381.     member([_,_,_]-RefNucl,Nuclei2),
  382.     not(logically_erased(sent_C,RefNucl)),
  383.     clause(sent_C(C),true,RefNucl),
  384.         C=cl(_,_,By,_,Sp,Ds,_,_,Pr),
  385.     not(not(get_hm_nucleus_3(By))).
  386.      get_hm_nucleus_1(N,S,C4,Ref) :-
  387.     clause(sent_C(cl(S,N,by([L1,L2|C1],V,V,_,_),_,_,_,_,_,_)),true,Ref),
  388.     get_hm_nucleus_2([L1,L2|C1],C2),
  389.         ground(C2,C3,_,_),
  390.         keysort(C3,C4).
  391.      get_hm_nucleus_2([],[]) :- !.
  392.      get_hm_nucleus_2([L1|C1],[L2-dummy|C2]) :-
  393.     (L1=not(L1n) -> (
  394.       L2=L1n
  395.     ); (
  396.       L2=L1
  397.     )),
  398.     get_hm_nucleus_2(C1,C2).
  399.      get_hm_nucleus_3(by(Cn1,V1,V1,_,_)) :-
  400.     create_LnkLits(Cn1,LnkLits),
  401.     hm_literal_14(Cn1,LnkLits),
  402.     !.
  403.  
  404. %%% Hyper-match the nucleus.
  405. %%% If UR round, do nothing if
  406. %%%    1. the nucleus is not original input clause.
  407. %%%    2. the nucleus is original input clause, but unit.
  408.      hm_clause(cl(_,_,by(Cn1,_,_,_,_),0,CS1,_,CT1,_,_),RefNucl,_,_) :- 
  409.     current_support(sup(_,_,_,1)), 
  410.          check_throw_nucleus(0,CT1,Cn1,CS1,RefNucl),
  411.     !, fail.
  412.      hm_clause(cl(_,_,by([_],_,_,_,_),1,_,_,_,_,_),_,_,_) :- 
  413.     current_support(sup(_,_,_,1)), 
  414.     !, fail.
  415.      hm_clause(cl(CSize1,_,by(Cn1,V11,V11,V1,W1),CI1,CS1,CR1,CT1,CF1,CP1),
  416.         RefNucl,RSLists,RGLists) :-
  417.     print_nucleus(Cn1,V1,CS1,CR1,CF1),
  418.     decide_unit(Cn1,U),
  419.          check_throw_nucleus(CI1,CT1,Cn1,CS1,RefNucl),
  420.     negate_clause(Cn1,NCn1),
  421.     !,
  422.          hm_clause1(RefNucl,U,CF1,Cn1,NCn1,W1,CS1,CR1,RSLists,RGLists,
  423.         CF2,Cn2a,W2a,DFlag,CS2,CR2),
  424.     rewrite_clause(Cn2a,CS2,CR2,1,Cn2,_),
  425.     hm_clause2(Cn2,W2a,W2),
  426.     hm_clause3(RefNucl,U,CSize1,CP1,CF2,Cn2,V1,W2,DFlag,CS2,CR2).
  427.      hm_clause2(_,W2,W2) :-
  428.     not(rwr(_,_,_,_)),
  429.     !.
  430.      hm_clause2(Cn2,_,W2) :-
  431.     vars_literals(Cn2,W2),
  432.     !.
  433.      hm_clause3(RefNucl,U,CSize1,CP1,CF2,Cn2,V1,W2,DFlag,CS2,CR2) :-
  434.     process_HM(RefNucl,U,CSize1,CP1,CF2,Cn2,V1,W2,DFlag,CS2,CR2),
  435.     check_empty_hm(Cn2).
  436.      hm_clause3(_,_,_,_,_,_,_,_,_,_,_) :-
  437.     is_time_overflow.
  438.  
  439. %%% If an empty hyper-match is generated, assert information into database.
  440.      check_empty_hm([]) :-
  441.     assert_tryresult('unsatisfiable'),
  442.     assert_prooftype('HM'), !.
  443.      check_empty_hm(_).
  444.  
  445. %%% If sliding priority is used.
  446.      process_HM(RefNucl,U,CSize1,CP1,F2,Cn2,V1,W2,DFlag,CS2,CR2) :-
  447.     slidepriority,
  448.     !, prio_test(U,CP1,Cn2,DFlag,V1,CS2,CR2,CP2),
  449.     calculate_new_size(U,CSize1,Cn2,DFlag,V1,CSize2), 
  450.     make_varstail(U,V1,W2,V2),
  451.     !, check_numbervars(V2,'Number of variables overflows in instances !'),
  452.     !, totalhm_test(RefNucl,U,CSize2,CP2,F2,Cn2,V2,W2,CS2,CR2), !.
  453. %%% If fixed priority is used.
  454.      process_HM(RefNucl,U,CSize1,CP1,F2,Cn2,V1,W2,DFlag,CS2,CR2) :-
  455.     fixed_priority,
  456.     !,
  457.     prio_test(U,CP1,Cn2,Dflag,V1,CS2,CR2,CP2),
  458.     calculate_new_size(U,CSize1,Cn2,DFlag,V1,CSize2),
  459.     make_varstail(U,V1,W2,V2),
  460.     !, check_numbervars(V2,'Number of variables overflows in instances !'),
  461.     !, noslide_update_HM(RefNucl,U,CSize2,CP1,F2,Cn2,V2,W2,CS2,CR2), !.
  462. %%% If no fixed or sliding priority.
  463.      process_HM(RefNucl,U,CSize1,CP1,F2,Cn2,V1,W2,DFlag,CS2,CR2) :-
  464.     calculate_new_size(U,CSize1,Cn2,DFlag,V1,CSize2),
  465.     make_varstail(U,V1,W2,V2),
  466.     !, check_numbervars(V2,'Number of variables overflows in instances !'),
  467.     !, noslide_update_HM(RefNucl,U,CSize2,CP1,F2,Cn2,V2,W2,CS2,CR2), !.
  468.  
  469. %%% N1 is used for recording if a literal in a hyper-match is unit-deleted
  470. %%%     or not. If it is unit deleted, the correponding element at appropriate
  471. %%%     position is 1, otherwise it is 0.
  472. %%% CR1 is separated into two sublists: Ord1 and Ord2. Ord1 are the literals
  473. %%%    to be matched by supported mates. Ord2 are the literals to be
  474. %%%    matched by any mates. We matched Ord1 first, then Ord2 for efficiency
  475. %%%    purpose.
  476.      hm_clause1(RefNucl,U,F1,Cn1,NCn1,W1,CS1,CR1,RSLists,RGLists,
  477.         F2,Cn2,W2,DFlag,CS2,CR2) :-
  478.     clause_part2(CS1,CR1,CSM1,CRM1),
  479.     matord(NCn1,Ord1,Ord2,W1,WO1,WO2,N1,NOrd1,NOrd2),
  480.     !,
  481.          hm_clause1_2(Ord1,Ord2,WO1,WO2,NOrd1,NOrd2,RefNucl,U,
  482.         RSLists,RGLists,CSM1,CRM1,CS2,CRM2,Cn1),
  483.     hm_clause1_3(N1,F1,Cn1,W1,CR1,CS2,CRM2,F2,Cn2,W2,DFlag,CR2).
  484.  
  485. %%% If the current round is user support round.
  486.      hm_clause1_2(Ord1,Ord2,WO1,WO2,NOrd1,NOrd2,RefNucl,U,
  487.         RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  488.     current_support(sup(1,0,0,0)),
  489.     !,
  490.     hm_user(Ord1,WO1,NOrd1,RefNucl,U,RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1).
  491. %%% If the current round is UR support round.
  492.      hm_clause1_2(Ord1,Ord2,WO1,WO2,NOrd1,NOrd2,RefNucl,U,
  493.         RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  494.     current_support(sup(_,_,_,1)),
  495.     !,
  496.     hm_ur(Ord1,WO1,NOrd1,RefNucl,U,RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1).
  497. %%% Otherwise.
  498.      hm_clause1_2(Ord1,Ord2,WO1,WO2,NOrd1,NOrd2,RefNucl,U,
  499.         RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  500.          hm_bf(Ord1,Ord2,WO1,WO2,NOrd1,NOrd2,RefNucl,U,RSLists,RGLists,
  501.         CS1,CR1,CS2,CR2,Cn1).
  502.  
  503. %%% For UR, we take one literal unmatched, then match the other literals
  504. %%%    with unit clauses.
  505. %%% In order to match ground literals first, we have to change the algorithm.
  506. %%%  hm_ur([Ln1|Lns1],[0|Ts1],RefNucl,U,RSLists,RGLists,CS1,CR1,CS2,CR2) :-
  507. %%%    hm_literals(Lns1,U,RefNucl,CS1,CR1,0,RSLists,Ts1,CS2,CR2).
  508. %%%  hm_ur([Ln1|[Ln2|Lns1]],[T1|Ts1],RefNucl,U,
  509. %%%        RSLists,RGLists,CS1,CR1,CS2,CR2) :-
  510. %%%    hm_literal(U,RefNucl,Ln1,CS1,CR1,0,RSLists,T1,CSM,CRM),
  511. %%%       hm_ur([Ln2|Lns1],Ts1,RefNucl,U,RSLists,RGLists,CSM,CRM,CS2,CR2).
  512. %%%
  513.      hm_ur([Ln1|Lns1],[W1|Ws1],[0|Ts1],RefNucl,U,
  514.         RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  515.     create_LnkLits(Cn1,LnkLits),
  516.     update_LnkLits(Cn1,Ln1,LnkLits,0),
  517.     hm_literals(Lns1,Ws1,U,RefNucl,CS1,CR1,0,RSLists,Ts1,CS2,CR2,Cn1,
  518.         LnkLits).
  519.      hm_ur([Ln1|[Ln2|Lns1]],[W1|Ws1],[T1|Ts1],RefNucl,U,
  520.         RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  521.          hm_ur_1([Ln2|Lns1],Ws1,Ts1,RefNucl,U, RSLists,RGLists,CS1,CR1,
  522.         [Ln1|KL1],[W1|KW1],[T1|KT1],KL1,KW1,KT1,CS2,CR2,Cn1).
  523.      hm_ur_1([Ln1|Lns1],[W1|Ws1],[0|Ts1],RefNucl,U, RSLists,RGLists,CS1,CR1,
  524.         KL1,KW1,KT1,Lns1,Ws1,Ts1,CS2,CR2,Cn1) :-
  525.     create_LnkLits(Cn1,LnkLits),
  526.     update_LnkLits(Cn1,Ln1,LnkLits,0),
  527.     hm_literals(KL1,KW1,U,RefNucl,CS1,CR1,0,RSLists,KT1,CS2,CR2,Cn1,
  528.         LnkLits).
  529.      hm_ur_1([Ln1|[Ln2|Lns1]],[W1|Ws1],[T1|Ts1],RefNucl,U, RSLists,RGLists,
  530.         CS1,CR1,KL1,KW1,KT1,[Ln1|KL2],[W1|KW2],[T1|KT2],CS2,CR2,Cn1) :-
  531.          hm_ur_1([Ln2|Lns1],Ws1,Ts1,RefNucl,U, RSLists,RGLists,
  532.         CS1,CR1,KL1,KW1,KT1,KL2,KW2,KT2,CS2,CR2,Cn1).
  533.  
  534. %%% For user support, we match one literal with user supported mates, then
  535. %%%    match the other literals with any mates.
  536. %%% In order to match ground literals first, we have to change the algorithm.
  537. %%%  hm_user([Ln1|Lns1],[T1|Ts1],RefNucl,U,RSLists,RGLists,CS1,CR1,CS2,CR2) :-
  538. %%%    hm_literal(U,RefNucl,Ln1,CS1,CR1,0,RSLists,T1,CSM,CRM),
  539. %%%    hm_literals(Lns1,U,RefNucl,CSM,CRM,1,RGLists,Ts1,CS2,CR2).
  540. %%%  hm_user([Ln1|[Ln2|Lns1]],[T1|Ts1],RefNucl,U,
  541. %%%        RSLists,RGLists,CS1,CR1,CS2,CR2) :-
  542. %%%    hm_literal(U,RefNucl,Ln1,CS1,CR1,1,RGLists,T1,CSM,CRM),
  543. %%%       hm_user([Ln2|Lns1],Ts1,RefNucl,U,RSLists,RGLists,CSM,CRM,CS2,CR2).
  544. %%%
  545.      hm_user([Ln1|Lns1],[W1|Ws1],[T1|Ts1],RefNucl,U,
  546.                 RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  547.     create_LnkLits(Cn1,LnkLits),
  548.     hm_user_literal_U(W1,Ws1,U,RefNucl,Ln1,CS1,CR1,0,RSLists,T1,Ws2,
  549.         CSM,CRM,Cn1,Lns1,LnkLits),
  550.     hm_literals(Lns1,Ws2,U,RefNucl,CSM,CRM,1,RGLists,Ts11,CS2,CR2,Cn1,
  551.         LnkLits).
  552.      hm_user([Ln1|[Ln2|Lns1]],[W1|Ws1],[T1|Ts1],RefNucl,U,
  553.                 RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  554.          hm_user_1([Ln2|Lns1],Ws1,Ts1,RefNucl,U,RSLists,RGLists,CS1,CR1,
  555.         [Ln1|KL1],[W1|KW1],[T1|KT1],KL1,KW1,KT1,CS2,CR2,Cn1).
  556.  
  557.      hm_user_1([Ln1|Lns1],[W1|Ws1],[T1|Ts1],RefNucl,U, RSLists,RGLists,CS1,CR1,
  558.         KL1,KW1,KT1,Lns1,Ws1,Ts1,CS2,CR2,Cn1) :-
  559.     create_LnkLits(Cn1,LnkLits),
  560.     hm_user_literal_U(W1,Ws1,U,RefNucl,Ln1,CS1,CR1,0,RSLists,T1,Ws2,
  561.         CSM,CRM,Cn1,Lns1,LnkLits),
  562.     hm_literals(KL1,KW1,U,RefNucl,CSM,CRM,1,RGLists,KT1,CS2,CR2,Cn1,
  563.         LnkLits).
  564.      hm_user_1([Ln1|[Ln2|Lns1]],[W1|Ws1],[T1|Ts1],RefNucl,U,RSLists,RGLists,
  565.         CS1,CR1,KL1,KW1,KT1,[Ln1|KL2],[W1|KW2],[T1|KT2],CS2,CR2,Cn1) :-
  566.          hm_user_1([Ln2|Lns1],Ws1,Ts1,RefNucl,U,RSLists,RGLists,
  567.         CS1,CR1,KL1,KW1,KT1,KL2,KW2,KT2,CS2,CR2,Cn1).
  568.  
  569.      hm_user_literal_U(W1,Ws1,U,RefNucl,Ln1,CS1,CR1,Type,RSLists,T1,Ws1,
  570.         CS2,CR2,Cn1,Ls1,LnkLits) :-
  571.     var(W1),
  572.     !, hm_literal(U,RefNucl,Ln1,CS1,CR1,Type,RSLists,T1,CS2,CR2,Cn1,
  573.         LnkLits),
  574.     !.
  575.      hm_user_literal_U(_,Ws1,U,RefNucl,Ln1,CS1,CR1,Type,RSLists,T1,Ws2,
  576.         CS2,CR2,Cn1,Ls1,LnkLits) :-
  577.     hm_literal(U,RefNucl,Ln1,CS1,CR1,Type,RSLists,T1,CS2,CR2,Cn1,LnkLits),
  578.     w1_w2(Ws1,Ws2).
  579.  
  580. %%% For forward support, we match all negative literals with forward
  581. %%%     supported mates, then mathc the other literals with any mates.
  582. %%% For backward support, we match all positive literals with backward
  583. %%%     supported mates, then mathc the other literals with any mates.
  584.      hm_bf(Ord1,Ord2,WO1,WO2,NOrd1,NOrd2,
  585.         RefNucl,U,RSLists,RGLists,CS1,CR1,CS2,CR2,Cn1) :-
  586.     create_LnkLits(Cn1,LnkLits),
  587.     hm_literals(Ord1,WO1,U,RefNucl,CS1,CR1,0,RSLists,NOrd1,CSM,CRM,Cn1,
  588.         LnkLits),
  589.     w1_w2(WO2,WO3),
  590.     hm_literals(Ord2,WO3,U,RefNucl,CSM,CRM,1,RGLists,NOrd2,CS2,CR2,Cn1,
  591.         LnkLits).
  592.  
  593.  
  594. %%% Check if it is user supported if it is required so.
  595. %%% Delete all literals that are unit deleted, i.e., the litearls
  596. %%%    whose corresponding entries in N1 are 1s.
  597. %%% Delete any duplicate literals in the hyper-match.
  598. %%% Check literal bound.
  599. %%% Adjust user distance.
  600. %%% Check relevance bound.
  601.      hm_clause1_3(N1,F1,Cn1,W1,CR1,CS2,CRM2,F2,Cn2,W2,DFlag,CR2) :-
  602.     check_supp_u(CS2),
  603.     literals_remain_3(N1,Cn1,W1,F1,CnM,WM,FM,DFlag), 
  604.     delete_replicate_literals_3(CnM,WM,FM,Cn2,W2,F2),
  605.     adjust_userdist(CRM2,CR1,CR2), 
  606.     !, check_rel_clause(CR1,Cn2,CR2), !.
  607.  
  608. %%% LITSALL_HM ROUTINES:
  609. %%%
  610. %%% The format for literal is:
  611. %%%    lit_G(U,lby(Ln1,V21,V22,Wn2),CS1,CR1)
  612. %%% U = 1 if the literal comes from a unit clause.
  613. %%% U = 0 if the literal comes from a non-unit clause.
  614. %%%
  615. %%% The idea is that we collect a set of literals. No repetition of the
  616. %%% literals are allowed. If two literals coming from different sources
  617. %%% and have different S and R, then we update S and R to reflect the
  618. %%% least distance to the support sets for calculating relevance and the 
  619. %%% most possibility to be supported for hyper-matching.
  620. %%%
  621. %%% Comments:
  622. %%%    The following procedure is used if unit_resolution is specified.
  623. %%%    If a literal comes from a unit clause, it is inserted into the
  624. %%%        database directly without duplicate checking because
  625. %%%        we know that there should be no duplicates after the
  626. %%%        unit subsumption and unit simplification.
  627. %%%    If a literal comes from a non-unit clause, we don't need to 
  628. %%%        check the duplicates against the unit-clause literals
  629. %%%        because of the reason stated above. However, we need
  630. %%%        to check duplicates against the other non-unit-clause 
  631. %%%        literals.
  632. %%% For efficiency, we do for non-unit clauses first, then for unit clauses.
  633. %%%
  634. %%% Instance deletion: If instance deletion is specified, then we do the
  635. %%%    following operation. If a literal L1 is an instance of L2, and
  636. %%%    L1 is not a unit clause, then delete L1.
  637. %%%    
  638.  
  639.      litsall_hm :-
  640.     not(not(litsall_hm_1)),
  641.     !.
  642.  
  643.      litsall_hm_1 :-
  644.     current_support(sup(_,_,_,1)),
  645.     litsall_hm_ur, !.
  646.      litsall_hm_1 :-
  647.     litsall_hm_ubf, !,
  648.          instdel_lits, !.
  649.  
  650. %%% If UR is specified, then we only have to find the literals from unit
  651. %%%    clauses.
  652. %%% Furthermore, we make the literal list as lit_S directly.
  653.      litsall_hm_ur :-
  654.     sent_C(cl(_,_,by([Ln1],V11,V12,_,[Wn1]),_,CS1,CR1,_,_,_)),
  655.     assertz(lit_S(1,lby(Ln1,V11,V12,Wn1),CS1,CR1)),
  656.     fail.
  657.      litsall_hm_ur.
  658.  
  659. %%% If the round is not UR round.
  660. %%% litsall_hm_ubf1(T1,T2):
  661. %%%     T1 means the existing lit_G(T1,...) in database.
  662. %%%    T2 means the coming lit_G(T2,...).
  663.      litsall_hm_ubf :-
  664.     litsall_hm_ubf1(0,0),
  665.     litsall_hm_ubf2, !.
  666.  
  667. %%% Find literals for non-unit clauses.
  668.      litsall_hm_ubf1(T1,T2) :-    
  669.     sent_C(cl(_,_,by([Ln1,Ln2|Lns1],V11,V12,_,W1),_,CS1,CR1,_,_,_)),
  670.     litsall_hm_ubf1([Ln1,Ln2|Lns1],V11,V12,W1,CS1,CR1,T1,T2),
  671.     fail.
  672.      litsall_hm_ubf1(_,_).
  673.  
  674. %%% Process one literal each time.
  675.      litsall_hm_ubf1([],_,_,_,_,_,_,_).
  676.      litsall_hm_ubf1([Ln1|Lns1],V11,V12,[Wn1|Wns1],CS1,CR1,T1,T2) :-
  677.     \+ lit_copy(Ln1,V11,V12,Wn1,CS1,CR1,T1,T2),
  678.     assertz(lit_G(T2,lby(Ln1,V11,V12,Wn1),CS1,CR1)),
  679.     !,
  680.     litsall_hm_ubf1(Lns1,V11,V12,Wns1,CS1,CR1,T1,T2).
  681.      litsall_hm_ubf1([Ln1|Lns1],V11,V12,[Wn1|Wns1],CS1,CR1,T1,T2) :-
  682.     !,                % green cut.
  683.     litsall_hm_ubf1(Lns1,V11,V12,Wns1,CS1,CR1,T1,T2).
  684.  
  685. %%% Check duplicates.
  686.      lit_copy(Ln1,V11,V11,Wn1,CS1,CR1,T1,T2) :-
  687.     const_list(Wn1),
  688.     lit_G(T1,lby(Ln1,V21,V21,Wn2),CS2,CR2),
  689.     const_list(Wn2),
  690.     binary_max_ind(T1,T2,T3,Up),
  691.     max_CS_ind(CS2,CS1,CS3,Up),
  692.     min_CR_ind(CR2,CR1,CR3,Up),
  693.     lit_copy_1(Up,CS3,CR3,T3,Ln1).
  694.  
  695.      lit_copy_1(n,_,_,_,_) :- !.
  696.      lit_copy_1(_,CS3,CR3,T3,Ln1) :-
  697.     clause(lit_G(_,lby(Ln1,V21,V21,Wn2),_,_),true,Ref2),
  698.     const_list(Wn2),
  699.     clause(lit_G(_,LBY_2,_,_),true,Ref2),
  700.     erase(Ref2),
  701.     assertz(lit_G(T3,LBY_2,CS3,CR3)), !.
  702.  
  703. %%% Find literals of unit clauses.
  704. %%% If unit resolution is specified, we don't need to check the duplicates
  705. %%%    for the literals from unit clauses.
  706.      litsall_hm_ubf2 :-
  707.     sent_C(cl(_,_,by([Ln1],V11,V12,_,[Wn1]),_,CS1,CR1,_,_,_)),
  708.     assertz(lit_G(1,lby(Ln1,V11,V12,Wn1),CS1,CR1)),
  709.     fail.
  710.      litsall_hm_ubf2.
  711.  
  712. %%% Delete literal instances.
  713. %%% To check if a literal D is an instance of C, there are 4 cases:
  714. %%% 1. D unit, C unit. Impossible because of unit subsumption.
  715. %%% 2. D unit, C not unit. Do not delete D.
  716. %%% 3. D not unit, C unit. Impossible because of unit subsumption.
  717. %%% 4. D not unit, C not unit. Only this case has to be considered.    
  718.      instdel_lits :-
  719.     \+ delete_all_instances,
  720.     \+ delete_nf_instances, !.
  721.      instdel_lits :-
  722.     abolish(lit_G1,3),
  723.     instdel_lits_1,
  724.     abolish(lit_G1,3).
  725.  
  726.      instdel_lits_1 :-
  727.     clause(lit_G(0,lby(Ln1,V11,V11,Wn1),_,_),true,Ref),
  728.     get_lit_G_data(Ref,CS1,CR1),
  729.     const_list(Wn1),
  730.     retract_lit_G(LBY2),
  731.     instdel_lits_ckinst(Ln1,CS1,CR1,lit_S(0,LBY2,CS1,CR1)), fail.
  732.      instdel_lits_1 :-
  733.     retract(lit_S(T,LBY,S,R)),
  734.     assertz(lit_G(T,LBY,S,R)),
  735.     fail.
  736.      instdel_lits_1.
  737.  
  738.      retract_lit_G(LBY2) :-
  739.     retract(lit_G(0,LBY2,_,_)), !.
  740.  
  741.      instdel_lits_ckinst(Ln1,CS1,CR1,L1) :-
  742.     delete_all_instances,
  743.     instdel_lits_ckinst_all(Ln1,CS1,CR1,L1), !.
  744.      instdel_lits_ckinst(Ln1,CS1,CR1,L1) :-
  745.     delete_nf_instances,
  746.     instdel_lits_ckinst_nf(Ln1,CS1,CR1,L1), !.
  747.  
  748.      instdel_lits_ckinst_all(Ln1,CS1,CR1,_) :-
  749.     instdel_lits_lit_inst(Ln1,CS1,CR1).
  750.      instdel_lits_ckinst_all(_,_,_,L1) :-
  751.     assertz(L1).
  752.  
  753.      instdel_lits_ckinst_nf(Ln1,sp(S11,S12,0),CR1,_) :-
  754.     instdel_lits_lit_inst(Ln1,sp(S11,S12,0),CR1).
  755.      instdel_lits_ckinst_nf(_,_,_,L1) :-
  756.     assertz(L1).
  757.  
  758.      instdel_lits_lit_inst(Ln1,CS1,CR1) :-
  759.     clause(lit_G(0,lby(Ln1,V21,V21,_),_,_),true,Ref2),
  760.     get_lit_G_data(Ref2,CS2,CR2),
  761.     instdel_lits_lit_inst_2('G',CS1,CR1,Ln1,CS2,CR2).
  762.      instdel_lits_lit_inst(Ln1,CS1,CR1) :-
  763.     lit_S(0,lby(Ln1,V21,V21,_),CS2,CR2),
  764.     instdel_lits_lit_inst_2('S',CS1,CR1,Ln1,CS2,CR2).
  765.  
  766.      instdel_lits_lit_inst_2(_,sp(1,_,_),_,_,sp(0,_,_),_) :- !, fail.
  767.      instdel_lits_lit_inst_2(_,sp(0,1,_),_,_,sp(_,0,_),_) :- !, fail.
  768.      instdel_lits_lit_inst_2(T,CS1,CR1,Ln1,CS2,CR2) :-
  769.     max_CS_ind(CS2,CS1,CS3,Up),
  770.     min_CR_ind(CR2,CR1,CR3,Up),
  771.     instdel_lits_lit_inst_1(T,Up,Ln1,CS3,CR3).
  772.  
  773.      instdel_lits_lit_inst_1(_,n,_,_,_) :- !.
  774.      instdel_lits_lit_inst_1('G',_,Ln1,CS3,CR3) :-
  775.     clause(lit_G(0,lby(Ln1,V21,V21,_),_,_),true,Ref2),
  776.     update_lit_G_data(Ref2,CS3,CR3).
  777.      instdel_lits_lit_inst_1('S',_,Ln1,CS3,CR3) :-
  778.     clause(lit_S(0,lby(Ln1,V21,V21,_),_,_),true,Ref2),
  779.     clause(lit_S(0,LBY2,_,_),true,Ref2),
  780.     erase(Ref2),
  781.     assertz(lit_S(0,LBY2,CS3,CR3)).
  782.  
  783.     update_lit_G_data(Ref,CS,CR) :-
  784.     retract(lit_G1(Ref,_,_)),
  785.     assertz(lit_G1(Ref,CS,CR)),
  786.     !.
  787.     update_lit_G_data(Ref,CS,CR) :-
  788.     assertz(lit_G1(Ref,CS,CR)),
  789.     !.
  790.  
  791.     get_lit_G_data(Ref,CS,CR) :-
  792.     lit_G1(Ref,CS,CR),
  793.     !.
  794.     get_lit_G_data(Ref,CS,CR) :-
  795.     clause(lit_G(_,_,CS,CR),true,Ref),
  796.     !.
  797.  
  798. %%% SUPPORTED_MATES
  799. %%%
  800. %%% Find out supported mates.
  801. %%% If UR then do nothing.
  802.      supported_mates :-
  803.     current_support(sup(_,_,_,1)), !.
  804.      supported_mates :-
  805.     current_support(sup(1,0,0,0)),
  806.     supported_mates_u, !.
  807.      supported_mates :-
  808.     current_support(sup(_,1,0,_)),
  809.     supported_mates_b, !.
  810.      supported_mates :-
  811.     current_support(sup(_,0,1,_)),
  812.     supported_mates_f, !.
  813.      supported_mates :-
  814.     current_support(sup(_,1,1,_)),
  815.     supported_mates_bf.
  816.  
  817. %%% Find out user supported literals.
  818.      supported_mates_u :-
  819.     lit_G(UG,P,sp(1,S2,S3),R),
  820.     assertz(lit_S(UG,P,sp(1,S2,S3),R)),
  821.     fail.
  822.      supported_mates_u.
  823.  
  824. %%% Find out backward supported negative literals.
  825.      supported_mates_b :-
  826.     lit_G(UG,lby(P,V11,V12,W1),sp(S1,1,S3),R),
  827.     negative_lit(P),
  828.     assertz(lit_S(UG,lby(P,V11,V12,W1),sp(S1,1,S3),R)),
  829.     fail.
  830.      supported_mates_b.
  831.  
  832. %%% Find out forward supported positive literals.
  833.      supported_mates_f :-
  834.     lit_G(UG,lby(P,V11,V12,W1),sp(S1,S2,1),R),
  835.     \+ negative_lit(P),
  836.     assertz(lit_S(UG,lby(P,V11,V12,W1),sp(S1,S2,1),R)),
  837.     fail.
  838.      supported_mates_f.
  839.  
  840. %%% Find out backward supported negative and forward supported 
  841. %%%     positive literals.
  842.      supported_mates_bf :-
  843.     supported_mates_b,
  844.     leave_mates_f.
  845.  
  846.      leave_mates_f :-
  847.     clause(lit_G(_,lby(P,_,_,_),sp(_,_,S3),_),true,Ref1),
  848.     \+ positive_f_mate(P,S3),
  849.     erase(Ref1),
  850.     fail.
  851.      leave_mates_f.
  852.  
  853.      positive_f_mate(P,1) :-
  854.     \+ negative_lit(P).
  855.  
  856. %%% UPDATE_SENTC
  857. %%%
  858. %%% 1. duplicate checking
  859. %%% 2. copying sent_HM.
  860. %%%    
  861.  
  862.      update_sentC :-
  863.     const_list(Clist),
  864.     update_sentC_1(Clist),
  865.     sentHM_to_sentC_a.
  866.  
  867. %%% Pick one sent_T at a time.
  868.      update_sentC_1(Clist) :-
  869.     retract(sent_T(C1)),
  870.     update_sentC_3(C1,Clist),
  871.     fail.
  872.      update_sentC_1(_).
  873.  
  874. %%% Duplicate check against sent_C.
  875.      update_sentC_3(cl(CSize1,CN1,by(Cn1,V11,V11,Clist,_),_,CS1,CR1,
  876.         CT1,F1,pr(_,_,PL1,_,PX1)),Clist) :-
  877.     sent_C(cl(CSize1,CN1,by(Cn1,V21,V21,Clist,_),CI2,CS2,CR2,CT2,F2,
  878.         pr(_,_,PL2,_,PX2))),
  879.     min_ind(PL2,PL1,PL3,Up),
  880.     min_ind(PX2,PX1,PX3,Up),
  881.     binary_max_ind(CT2,CT1,CT3,Up),
  882.     min_Flags_ind(F2,F1,F3,Up),
  883.     max_CS_ind(CS2,CS1,CS3,Up),
  884.     min_CR_ind(CR2,CR1,CR3,Up),
  885.     update_sentC_31(Up,Cn1,Clist,PL3,PX3,F3,CS3,CR3,CI2,CT3), !.
  886.      update_sentC_3(C1,_) :-
  887.     asserta(sent_C(C1)), !.
  888.  
  889.  
  890. %%% If the information is not changed, do nothing.
  891.      update_sentC_31(n,_,_,_,_,_,_,_,_,_).
  892.      update_sentC_31(_,Cn1,Clist,PL3,PX3,F3,CS3,CR3,CI2,CT3) :-
  893.     clause(sent_C(cl(_,_,by(Cn1,V21,V21,Clist,_),_,_,_,_,_,_)),true,Ref2),
  894.     clause(sent_C(cl(CSize2,CN2,BY_2,_,_,_,_,_,pr(PS2,PD2,_,_,_))),
  895.         true,Ref2),
  896.     erase(Ref2),
  897.     priority_NewPR(CR3,PR3),
  898.     asserta(sent_C(cl(CSize2,CN2,BY_2,CI2,CS3,CR3,CT3,F3,
  899.         pr(PS2,PD2,PL3,PR3,PX3)))).
  900.  
  901. %%% FIXED and SLIDING PRIORITY
  902. %%%
  903. %%% priority test.
  904. %%% Calculate priority for the hyper-match.
  905. %%% Check if the priority computed is larger than the current priority
  906. %%%    bound.
  907.      prio_test(U,CP1,Cn2,DL,V1,CS2,CR2,CP2) :-
  908.     calculate_priority_HM(U,CP1,Cn2,DL,V1,CS2,CR2,CP2),
  909.     priority_bound(PrioBound),
  910.     !,
  911.     check_prioritybound(CP2,PrioBound).
  912.  
  913. %%% If the nucleus is unit clause and the hyper-match is not empty.
  914.      calculate_priority_HM(1,pr(PS1,PD1,_,_,PX1),[Ln2],_,_,CS2,CR2,
  915.         pr(PS1,PD1,PL2,PR2,PX2)) :-
  916.     not(rwr(_,_,_,_)),
  917.     literal_coef(LCoef),
  918.     relevance_coef(RCoef),
  919.     priority_PL(LCoef,[Ln2],CS2,PL2),
  920.     maximum(PX1,PL2,XX1),
  921.     priority_PR(RCoef,CR2,PR2),
  922.     maximum(XX1,PR2,PX2), !.
  923. %%% If the nuclues if ground.
  924.      calculate_priority_HM(_,pr(PS1,PD1,_,_,PX1),Cn2,0,V1,CS2,CR2,
  925.         pr(PS1,PD1,PL2,PR2,PX2)) :-
  926.     var(V1),
  927.     not(rwr(_,_,_,_)),
  928.     literal_coef(LCoef),
  929.     relevance_coef(RCoef),
  930.     priority_PL(LCoef,Cn2,CS2,PL2),
  931.     maximum(PX1,PL2,XX1),
  932.     priority_PR(RCoef,CR2,PR2),
  933.     maximum(XX1,PR2,PX2), !.
  934. %%% Otherwise.
  935.      calculate_priority_HM(_,_,Cn2,_,_,CS2,CR2,pr(PS,PD,PL,PR,P)) :-
  936.     depth_coef(DCoef),
  937.     size_coef(SCoef),
  938.     literal_coef(LCoef),
  939.     relevance_coef(RCoef),
  940.     priority_PS(SCoef,Cn2,PS),
  941.         priority_PD(DCoef,Cn2,PD),
  942.         priority_PL(LCoef,Cn2,CS2,PL),
  943.         priority_PR(RCoef,CR2,PR),
  944.         priority_clause(PS,PD,PL,PR,P), !.
  945.  
  946. %%% If the priority of the hyper-match M is larger than the current 
  947. %%%    priority bound, discard M.
  948.      check_prioritybound(pr(_,_,_,_,P),PrioBound) :-
  949.     P =< PrioBound.
  950.      check_prioritybound(_,_) :-
  951.     assert_once(over_priohm), !, fail.
  952.  
  953. %%% If the hyper-match is a duplicate, do nothing.
  954.      totalhm_test(_,_,CSize2,CP2,F2,Cn2,V2,_,CS2,CR2) :-
  955.     update_HM(CSize2,CP2,F2,Cn2,V2,CS2,CR2), !.
  956. %%% Check for unit conflict proof.
  957.      totalhm_test(_,_,_,_,_,Cn2,_,_,_,_) :-
  958.     (check_unit_conflict_C(Cn2); check_unit_conflict_HM(Cn2)),
  959.         !,
  960.     assert_tryresult('unsatisfiable'),
  961.     assert_prooftype('UC').
  962. %%% If the hyper-match is not a duplicate, check the number of hyper-matches
  963. %%%    already in database.
  964.      totalhm_test(RefNucl,U,CSize2,CP2,F2,Cn2,V2,W1,CS2,CR2) :-
  965.     prio_parameters(TotalHm,ExpectWU,TotalWU), !,
  966.     totalhm_test1(hm,RefNucl,U,CSize2,CP2,F2,Cn2,V2,W1,CS2,CR2,
  967.         TotalHm,ExpectWU,TotalWU),
  968.     !.
  969.  
  970. %%% Obtain some information from database.
  971.      prio_parameters(TotalHm,ExpectWU,TotalWU) :-
  972.     total_numhm(TotalHm),
  973.     wu_bound(ExpectWU),
  974.     total_wu(TotalWU).
  975.  
  976. %%% Test if the total hyper-matches in the session exceeds the hyper-match
  977. %%% bound.
  978. %%% If the total hyper-matches doesn't exceed the hyper-match bound, then
  979. %%% update counters and assert the hyper-match.
  980.      totalhm_test1(Type,RefNucl,U,CSize2,CP2,F2,Cn2,V2,W1,CS2,CR2,
  981.         TotalHm_1,ExpectWU,TotalWU_1) :-
  982.     add_PT2(CP2,TotalWU_1,TotalWU_2),
  983.     TotalWU_2 =< ExpectWU,
  984.     TotalHm_2 is TotalHm_1 + 1,
  985.     update_numhm_wu(TotalHm_2,TotalWU_2),
  986.     update_priowu(CP2),
  987.     proc_C(U,RefNucl,Cn2,V2,W1,CN2,Cn3,V21,V22,V3,W2),
  988.     !, check_literalbound(Type,CN2,CS2),
  989.     print_HM(Cn2,V2,CS2,CR2,F2),
  990.     assert_an_HM(Type,CSize2,CN2,by(Cn3,V21,V22,V3,W2),CS2,CR2,F2,CP2), !.
  991. %%% If the total hyper-matches exceeds the hyper-match bound, then
  992. %%% find out the maximum priority in the hyper-matches.
  993.      totalhm_test1(Type,RefNucl,U,CSize2,CP2,F2,Cn2,V2,W1,CS2,CR2,
  994.         TotalHm_1,ExpectWU,TotalWU_1) :-
  995.     max_priority(MaxPrio),
  996.     retract_priowu(pr(_,_,_,_MaxPrio),MaxNum,WUMaxPrio),
  997.     MaxPrioMinusOne is MaxPrio - 1,
  998.     update_priority_bound(MaxPrioMinusOne),
  999.     rmhm_prio(MaxPrio),
  1000.     rmrwr_prio(MaxPrio),
  1001.     rmpartinst_prio(MaxPrio),
  1002.     totalhm_test2(Type,RefNucl,U,CSize2,CP2,F2,Cn2,V2,W1,CS2,CR2,
  1003.         TotalHm_1,TotalWU_1,MaxPrio,MaxNum,WUMaxPrio).
  1004.  
  1005.  
  1006. %%% Make 0 for hyper-match, and 1 for instance of replace rules.
  1007.      assert_an_HM(hm,CSize2,CN2,BY2,CS2,CR2,F2,CP2) :-
  1008.     asserta(sent_HM(cl(CSize2,CN2,BY2,0,CS2,CR2,0,F2,CP2))).
  1009.      assert_an_HM(_,CSize2,CN2,BY2,CS2,CR2,F2,CP2) :-
  1010.     asserta(sent_HM(cl(CSize2,CN2,BY2,0,CS2,CR2,1,F2,CP2))).
  1011.  
  1012. %%% Update total number of hyper-matches and work units.
  1013.      update_numhm_wu(TotalHm_2,TotalWU_2) :-
  1014.     retract(total_numhm(_)),
  1015.     retract(total_wu(_)),
  1016.     assert(total_numhm(TotalHm_2)),
  1017.     assert(total_wu(TotalWU_2)).
  1018.  
  1019. %%% Update the number of hyper-matches with particular priority,
  1020. %%%    the priority itself, and the work-units of the priority.
  1021.      update_priowu(CP2) :-
  1022.     retract_priowu(CP2,NumHm_1,WU_1),
  1023.     add_PT2(CP2,WU_1,WU_2),
  1024.     NumHm_2 is NumHm_1 + 1,
  1025.     assert_priowu(CP2,NumHm_2,WU_2).
  1026.  
  1027.      retract_priowu(pr(_,_,_,_,Prio),NumHm,WU) :-
  1028.     retract(prio_wu(Prio,NumHm,WU)), !.
  1029.      retract_priowu(_,0,0).
  1030.  
  1031.      assert_priowu(pr(_,_,_,_,Prio),NewNumHm,NewWU) :-
  1032.     assert(prio_wu(Prio,NewNumHm,NewWU)).
  1033.  
  1034. %%% Update current priority bound.
  1035.      update_priority_bound(NewPr) :-
  1036.     retract(priority_bound(Pr)),
  1037.     assert(priority_bound(NewPr)).
  1038.  
  1039.  
  1040. %%% Find the maximum priority of non-input clauses.
  1041.      max_priority(MaxPrio) :-
  1042.     bagof1(P,(N1,N2)^prio_wu(P,N1,N2),Ps),
  1043.     max_list(Ps,MaxPrio).
  1044.     
  1045. %%% If the priority is identical to the largest priority.
  1046.      totalhm_test2(_,_,_,_,pr(_,_,_,_,MaxPrio),_,_,_,_,_,_,
  1047.         TotalHm_1,TotalWU_1,MaxPrio,MaxNum,WUMaxPrio) :-
  1048.     TotalHm_2 is TotalHm_1 - MaxNum,
  1049.     TotalWU_2 is TotalWU_1 - WUMaxPrio,
  1050.          update_numhm_wu(TotalHm_2,TotalWU_2), !.
  1051. %%% If the priority is not identical to the largest priority.
  1052.      totalhm_test2(Type,RefNucl,U,CSize2,CP2,F2,Cn2,V2,W1,CS2,CR2,
  1053.         TotalHm_1,TotalWU_1,MaxPrio,MaxNum,WUMaxPrio) :-
  1054.     TotalHm_2 is TotalHm_1 - MaxNum + 1,
  1055.     YY is TotalWU_1 - WUMaxPrio,
  1056.     add_PT2(CP2,YY,TotalWU_2),
  1057.          update_numhm_wu(TotalHm_2,TotalWU_2),
  1058.         update_priowu(CP2),
  1059.     proc_C(U,RefNucl,Cn2,V2,W1,CN2,Cn3,V21,V22,V3,W2),
  1060.     !, check_literalbound(Type,CN2,CS2),
  1061.     print_HM(Cn2,V2,CS2,CR2,F2),
  1062.     assert_an_HM(Type,CSize2,CN2,by(Cn3,V21,V22,V3,W2),CS2,CR2,F2,CP2), !.
  1063.  
  1064.      add_PT2(pr(_,_,_,_,PT),Old,New) :-
  1065.     New is Old + PT, !.
  1066.  
  1067. %%% Delete clauses having P too big and it is not an input clause.
  1068.      rmhm_prio(P) :-
  1069.     clause(sent_C(cl(_,_,by(C1,V1,V1,V2,_),0,_,_,_,_,pr(_,_,_,_,P))),true,
  1070.         Cref),
  1071.     not(logically_erased(sent_C,Cref)),
  1072.     logically_erase(sent_C,Cref),
  1073.     fail.
  1074.      rmhm_prio(P) :-
  1075.     clause(sent_HM(cl(_,_,by(C1,V1,V1,V2,_),0,_,_,_,_,pr(_,_,_,_,P))),true,
  1076.         Cref),
  1077.     erase(Cref),
  1078.     fail.
  1079.      rmhm_prio(P) :-
  1080.     clause(sent_T(cl(_,_,by(C1,V1,V1,V2,_),0,_,_,_,_,pr(_,_,_,_,P))),true,
  1081.         Cref),
  1082.     erase(Cref),
  1083.     fail.
  1084.      rmhm_prio(_) :-
  1085.          assert_once(over_priohm).
  1086.  
  1087. %%% Calculate size for hyper-match.
  1088. %%% Unit nucleus.
  1089.      calculate_new_size(1,CSize1,[_],_,_,CSize1) :-
  1090.     not(rwr(_,_,_,_)),
  1091.     !.
  1092. %%% Empty hyper-match.
  1093.      calculate_new_size(_,_,[],_,_,0) :- !.
  1094. %%% Ground nucleus and no literal deletion.
  1095.      calculate_new_size(_,CSize1,_,0,V1,CSize1) :-
  1096.     var(V1),
  1097.     !.
  1098. %%% Otherwise.
  1099.      calculate_new_size(_,_,Cn2,_,_,CSize2) :-
  1100.     clause_size(Cn2,CSize2), !.
  1101.  
  1102. %%% Nucleus is unit.
  1103.      proc_C(1,Ref,[_],_,_,CN3,Cn3,V31,V32,V3,W3) :-
  1104.     clause(sent_C(cl(_,CN3,by(Cn3,V31,V32,V3,W3),_,_,_,_,_,_)),
  1105.         true,Ref),
  1106.     not(logically_erased(sent_C,Ref)),
  1107.     !.
  1108. %%% Empty hyper-match.
  1109.      proc_C(_,_,[],_,_,0,[],[],[],V3,[W3]) :- !.
  1110. %%% nucleus is not unit but hyper-match is ground.
  1111.      proc_C(_,_,Cn2,V2,_,0,Cn2,[],[],V3,W3) :-
  1112.     var(V2), 
  1113.     same_number_W1(Cn2,W3), !.
  1114. %%% Otherwise linearize the hyper-match.
  1115. %%% NOTE that we have already make the nucleus non-linearized by setting
  1116. %%%        V11 = V12
  1117. %%%     before.
  1118.      proc_C(_,_,Cn2,V2,W2,CV3,Cn3,V31,V32,V2,W3) :-  
  1119.     linearize_term(Cn2,Cn3,V31,V32),
  1120.     w1_w2(W2,W3),
  1121.     compute_V_lits(W3,0,CV3).
  1122.  
  1123. %%% Take as many entries as Cn2 from W2.
  1124.      same_number_W1([_|Cn2],[_|Ws3]) :-
  1125.          same_number_W1(Cn2,Ws3).
  1126.      same_number_W1([],[]).
  1127.  
  1128. %%% Calculate new W1 from old W1.
  1129.      w1_w2([W2|Ws2],[W3|Ws3]) :-
  1130.     vars_V1_V2(W2,W3), !,
  1131.     w1_w2(Ws2,Ws3).
  1132.      w1_w2([],[]).
  1133.  
  1134. %%% Calculate vars tail for hyper-matches.
  1135. %%% Unit hyper-match.
  1136.      make_varstail(1,V1,[_],V1) :- !.
  1137. %%% empty hyper-match.
  1138.      make_varstail(_,_,[],V1) :- !.
  1139.      make_varstail(_,_,W1,V2) :-
  1140.     vars_W1_V1(W1,V2), !.
  1141.  
  1142. %%% vars_V1_V2 calculates variable list V2 from a variable list V1.
  1143. %%% V1 is already a form with tail.
  1144. %%% V1 is for a hyper-match, it may not be a variable list due to the 
  1145. %%%    unification of nucleus to its mates.
  1146. %%% V2 keeps the tail of V1.
  1147.  
  1148.      vars_V1_V2(V1,V1) :- var(V1), !.
  1149.      vars_V1_V2(V1,V2) :-
  1150.     vars_V1_V2(V1,[],_,V2,Hole), !.
  1151.  
  1152.      vars_V1_V2(V,_,_,Hole,Hole) :- var(V), !.
  1153.      vars_V1_V2([L1|Ls1],Sofar_in,Sofar_out,V2,Hole) :-
  1154.     vars_V1_V2_elem(L1,Sofar_in,Sofar_mid,V2,Hole1),
  1155.     !,
  1156.     vars_V1_V2(Ls1,Sofar_mid,Sofar_out,Hole1,Hole).
  1157.  
  1158.      vars_V1_V2_elem(Term, Sofar_in, Sofar_in,Hole,Hole) :- 
  1159.     atomic(Term), !.
  1160.      vars_V1_V2_elem(Term, Sofar_in, Sofar_in,Hole,Hole) :- 
  1161.     var(Term),
  1162.     identical_member(Term, Sofar_in), !.
  1163.      vars_V1_V2_elem(Term, Sofar_in, [Term|Sofar_in],[Term|Hole],Hole) :-
  1164.          var(Term), !.
  1165.      vars_V1_V2_elem(Term, Sofar_in, Sofar_out,V2,Hole) :- 
  1166.     functor(Term, _, N),
  1167.     vars_V1_V2_elem(0,N,Term,Sofar_in,Sofar_out,V2,Hole).
  1168.  
  1169.      vars_V1_V2_elem(N,N,_,S,S,Hole,Hole) :- !.
  1170.      vars_V1_V2_elem(N1,N2,Term,Sofar_in,Sofar_out,V2,Hole) :-
  1171.     M is N1+1,
  1172.     arg(M,Term,Arg),
  1173.     vars_V1_V2_elem(Arg,Sofar_in,Sofar_mid,V2,Hole1),
  1174.     !,
  1175.     vars_V1_V2_elem(M,N2,Term,Sofar_mid,Sofar_out,Hole1,Hole).
  1176.  
  1177. %%% vars_W1_V1 calculates V1 from W1.
  1178.      vars_W1_V1(W1,V1) :-
  1179.     vars_W1_V1(W1,[],_,V1,Hole).
  1180.  
  1181.      vars_W1_V1([W1|Ws1],Sofar_In,Sofar_Out,V1,Hole) :-
  1182.     vars_W1_V1_2(W1,Sofar_In,Sofar_Mid,V1,Hole1), !,
  1183.     vars_W1_V1(Ws1,Sofar_Mid,Sofar_Out,Hole1,Hole).
  1184.      vars_W1_V1([],_,_,Hole,Hole).
  1185.  
  1186.      vars_W1_V1_2(W1,Sofar_In,Sofar_In,Hole,Hole) :- var(W1), !.
  1187.      vars_W1_V1_2([W1|Ws1],Sofar_In,Sofar_Out,V1,Hole) :- 
  1188.     vars_V1_V2_elem(W1,Sofar_In,Sofar_Mid,V1,Hole1),
  1189.     !,
  1190.     vars_W1_V1_2(Ws1,Sofar_Mid,Sofar_Out,Hole1,Hole).
  1191.  
  1192. %%% DUPLICATE CHECKING FOR HM
  1193. %%%
  1194. %%% If no dliding priority is specified, then we don't need to check the
  1195. %%% priorities, check the number of hyper-matches, and so forth.
  1196.      noslide_update_HM(_,_,CSize2,CP2,F2,Cn2,V2,_,CS2,CR2) :-
  1197.     update_HM(CSize2,CP2,F2,Cn2,V2,CS2,CR2), !.
  1198.      noslide_update_HM(_,_,_,_,_,Cn2,_,_,_,_) :-
  1199.     (check_unit_conflict_C(Cn2); check_unit_conflict_HM(Cn2)),
  1200.         !,
  1201.     assert_tryresult('unsatisfiable'),
  1202.     assert_prooftype('UC').
  1203.      noslide_update_HM(RefNucl,U,CSize2,CP2,F2,Cn2,V2,W1,CS2,CR2) :-
  1204.     proc_C(U,RefNucl,Cn2,V2,W1,CN2,Cn3,V21,V22,V3,W2),
  1205.     !, check_literalbound(hm,CN2,CS2),
  1206.     print_HM(Cn2,V2,CS2,CR2,F2),
  1207.     asserta(sent_HM(cl(CSize2,CN2,by(Cn3,V21,V22,V3,W2),
  1208.         0,CS2,CR2,0,F2,CP2))), !.
  1209.  
  1210. %%% First check sent_HM, then sent_T, then sent_C.
  1211. %%% The order is important.
  1212.      update_HM(CSize2,CP2,F2,Cn2,V2,CS2,CR2) :-
  1213.     const_list(V2),
  1214.          update_HM(CSize2,CP2,F2,Cn2,CS2,CR2).
  1215.  
  1216.      update_HM(CSize2,CP2,F2,Cn2,CS2,CR2) :-
  1217.     update_HM_1(CSize2,CP2,F2,Cn2,CS2,CR2).
  1218.      update_HM(CSize2,CP2,F2,Cn2,CS2,CR2) :-
  1219.     update_HM_2(CSize2,CP2,F2,Cn2,CS2,CR2).
  1220.      update_HM(CSize2,CP2,F2,Cn2,CS2,CR2) :-
  1221.     update_HM_3(CSize2,CP2,F2,Cn2,CS2,CR2).
  1222.  
  1223. %%% Duplicate check against sent_HM.
  1224.      update_HM_1(CSize1,pr(_,_,PL1,_,PX1),F1,Cn1,CS1,CR1) :-
  1225.     sent_HM(cl(CSize1,_,by(Cn1,V21,V21,V2,_),_,
  1226.         CS2,CR2,_,F2,pr(_,_,PL2,_,PX2))),
  1227.     const_list(V2),
  1228.     min_ind(PL2,PL1,PL3,Up),
  1229.     min_ind(PX2,PX1,PX3,Up),
  1230.     min_Flags_ind(F2,F1,F3,Up),
  1231.     max_CS_ind(CS2,CS1,CS3,Up),
  1232.     min_CR_ind(CR2,CR1,CR3,Up),
  1233.     update_HM_11(Up,Cn1,PL3,PX3,F3,CS3,CR3).
  1234.  
  1235.      update_HM_11(n,_,_,_,_,_,_) :- !.
  1236.      update_HM_11(_,Cn1,PL3,PX3,F3,CS3,CR3) :-
  1237.     clause(sent_HM(cl(_,_,by(Cn1,V21,V21,V2,_),_,_,_,_,_,_)),true,Ref2),
  1238.     const_list(V2),
  1239.     clause(sent_HM(cl(CSize2,CN2,BY_2,CI2,_,_,CT2,_,pr(PS2,PD2,_,_,_))),
  1240.         true,Ref2),
  1241.     erase(Ref2),
  1242.     priority_NewPR(CR3,PR3),
  1243.     asserta(sent_HM(cl(CSize2,CN2,BY_2,CI2,CS3,CR3,CT2,F3,
  1244.         pr(PS2,PD2,PL3,PR3,PX3)))).
  1245.  
  1246. %%% Duplicate check against sent_T.
  1247.      update_HM_2(CSize1,pr(_,_,PL1,_,PX1),F1,Cn1,CS1,CR1) :-
  1248.     sent_T(cl(CSize1,_,by(Cn1,V21,V21,V2,_),_,
  1249.         CS2,CR2,_,F2,pr(_,_,PL2,_,PX2))),
  1250.     const_list(V2),
  1251.     min_ind(PL2,PL1,PL3,Up),
  1252.     min_ind(PX2,PX1,PX3,Up),
  1253.     min_Flags_ind(F2,F1,F3,Up),
  1254.     max_CS_ind(CS2,CS1,CS3,Up),
  1255.     min_CR_ind(CR2,CR1,CR3,Up),
  1256.     update_HM_21(Up,Cn1,PL3,PX3,F3,CS3,CR3).
  1257.  
  1258.      update_HM_21(n,_,_,_,_,_,_) :- !.
  1259.      update_HM_21(_,Cn1,PL3,PX3,F3,CS3,CR3) :-
  1260.     clause(sent_T(cl(_,_,by(Cn1,V21,V21,V2,_),_,_,_,_,_,_)),true,Ref2),
  1261.     const_list(V2),
  1262.     clause(sent_T(cl(CSize2,CN2,BY_2,_,_,CI2,CT2,_,pr(PS2,PD2,_,_,_))),
  1263.         true,Ref2),
  1264.     erase(Ref2),
  1265.     priority_NewPR(CR3,PR3),
  1266.     asserta(sent_T(cl(CSize2,CN2,BY_2,CI2,CS3,CR3,CT2,F3,
  1267.         pr(PS2,PD2,PL3,PR3,PX3)))).
  1268.  
  1269. %%% Duplicate check against sent_C.
  1270. %%% If a duplicate found, store the hyper-match as sent_T.
  1271.      update_HM_3(CSize1,CP1,F1,Cn1,CS1,CR1) :-
  1272.     sent_C(cl(CSize1,_,by(Cn1,V21,V21,V2,_),_,_,_,_,_,_)),
  1273.     const_list(V2),
  1274.     clause(sent_C(cl(_,_,by(Cn1,V31,V31,V3,_),_,_,_,_,_,_)),
  1275.         true,Ref2),
  1276.     const_list(V3),
  1277.     not(logically_erased(sent_C,Ref2)),
  1278.     clause(sent_C(cl(_,CN1,BY_2,_,_,_,_,_,_)),true,Ref2),
  1279.     asserta(sent_T(cl(CSize1,CN1,BY_2,0,CS1,CR1,0,F1,CP1))).
  1280.  
  1281. %%% RELEVANCE TEST 
  1282. %%%
  1283. %%% relevance test.
  1284. %%% Two stages:
  1285. %%%    1. Test user distance =< RelBound
  1286. %%%    2. Test CR2 >= CR1
  1287. %%%
  1288.      check_rel_clause(Ds1,C,Ds2) :-
  1289.     check_rel_clause1(Ds1,C,Ds2),
  1290.     !.
  1291.      check_rel_clause(_,_,_) :-
  1292.     !, is_time_overflow.
  1293.      check_rel_clause1(ds(R11,R12,R13),Cn2,ds(R21,R22,R23)) :-
  1294.     relevance_bound(RelBound),
  1295.     check_rel_u(R21,RelBound),
  1296.     !,
  1297.     distance_equalR(R11,R12,R13,Cn2,RelBound),
  1298.     !,
  1299.     distance_ge(R21,R22,R23,R11,R12,R13), !.
  1300.  
  1301.      check_rel_u(R,RelBound) :-
  1302.     R =< RelBound, !.
  1303.      check_rel_u(_,_) :-
  1304.     assert_once(over_relevance), !, fail.
  1305.  
  1306. %%% if max(B+F,U) = RelBound,
  1307. %%%    then
  1308. %%%    1. if U = RelBound, it should be unit.
  1309. %%%    2. if B = RelBound, it should be all positive.
  1310. %%%    3. if F = RelBound, it should be all negative.
  1311.      distance_equalR(RelBound,_,_,[_,_|_],RelBound) :- !, fail.
  1312.      distance_equalR(_,RelBound,_,Cn2,RelBound) :- \+ posclause(Cn2), !, fail.
  1313.      distance_equalR(_,_,RelBound,Cn2,RelBound) :- \+ negclause(Cn2), !, fail.
  1314.      distance_equalR(_,_,_,_,_).
  1315.     
  1316.      distance_ge(R21,R22,R23,R11,R12,R13) :-
  1317.     R21 >= R11, !,
  1318.     R22 >= R12, !,
  1319.     R23 >= R13, !.
  1320.  
  1321. %%% check max(B+F,U) =< relevance after each literal match. 
  1322. %%% B+F is monotonically increasing, so there is no problem for B+F.
  1323. %%% But U is monotonically decreasing. This cause problem.
  1324. %%% So if max(B+F,U) test fails after the current literal matching, it
  1325. %%% is not necessarily that 
  1326. %%%    max(B+F,U)
  1327. %%% test will fail at the end of hyper-matching of a nucleus.
  1328. %%%
  1329. %%% Therefore, the only thing that we can do for testing the relevance
  1330. %%% after each literal matching is checking B+F. This automatically
  1331. %%% consider the case that the nucleus is in support set.
  1332.  
  1333.      check_rel_bf(ds(_,R12,R13)) :-
  1334.     relevance_bound(RelBound),
  1335.     YY is R12 + R13, !,
  1336.     check_rel_bf_2(YY,RelBound), !.
  1337.  
  1338.      check_rel_bf_2(YY,RelBound) :-
  1339.     YY =< RelBound, !.
  1340.      check_rel_bf_2(_,_) :-
  1341.     assert_once(over_relevance), !, fail.
  1342.  
  1343. %%% UPDATE CS AND CR
  1344. %%%
  1345. %%% onematch_SR updates the values of CS and CR.
  1346. %%% onematch_S updates the values of CS.
  1347. %%% For F, B, and UR:
  1348. %%%    if CS1 has 1, then CS2 has the same as CSM.
  1349. %%%    if CS1 has 0, then CS2 has 0.
  1350. %%% For U:
  1351. %%%    if CS1 has 1, then CS2 has 1.
  1352. %%%    if CS1 has 0, then CS2 has the same as CSM.
  1353. %%% onematch_R updates the values of CR.
  1354. %%%    if CR1 has 0, then CR2 has 0.
  1355. %%%     if CR1 has nonzero, then CR2 is CRM + 1.
  1356.  
  1357.      onematch_SR(Ln1,CS1,CR1,CSM,CRM,CS2,CR2) :-
  1358.     onematch_S(Ln1,CS1,CSM,CS2),
  1359.     onematch_R(CSM,Ln1,CR1,CRM,CR2), !.
  1360.  
  1361.      onematch_S(Ln1,sp(S11,S12,S13),sp(S21,S22,S23),sp(S31,S32,S33)) :-
  1362.     one_dominate(S11,S21,S31),
  1363.     zero_dominate_bf(Ln1,S12,S22,S32,S13,S23,S33).
  1364.  
  1365. %%% If one of inputs is 1, then the output is 1.
  1366.      one_dominate(1,_,1) :- !.
  1367.      one_dominate(_,S,S).
  1368.  
  1369. %%% If one of inputs is 0, then the output is 0.
  1370.      zero_dominate_bf(Ln1,S12,S22,S32,S13,_,S13) :-
  1371.     negative_lit(Ln1),
  1372.     zero_dominate(S12,S22,S32).
  1373.      zero_dominate_bf(Ln1,S12,_,S12,S13,S23,S33) :-
  1374.     zero_dominate(S13,S23,S33).
  1375.  
  1376.      zero_dominate(0,_,0) :- !.
  1377.      zero_dominate(_,S1,S1).
  1378.  
  1379.      onematch_R(sp(S21,_,_),Ln1,ds(R11,R12,R13),
  1380.         ds(R21,R22,R23),ds(R31,R32,R33)) :-
  1381.     cal_ud(S21,R11,R21,R31),
  1382.     cal_bfd(Ln1,R12,R22,R32,R13,R23,R33), !.
  1383.  
  1384.      cal_ud(_,0,_,0) :- !.
  1385. %%% If the mate is user supported,
  1386.      cal_ud(1,R11,R21,R31) :-
  1387.     RR is R21 + 1,
  1388.     minimum(R11,RR,R31).
  1389. %%% If the mate is not user supported,
  1390. %%%    user distance = current user distance
  1391.      cal_ud(0,R11,_,R11).
  1392.  
  1393.      cal_bfd(Ln1,R12,R22,R32,R13,_,R13) :-
  1394.     negative_lit(Ln1),
  1395.     cal_bf(R12,R22,R32), !.
  1396.      cal_bfd(_,R12,_,R12,R13,R23,R33) :-
  1397.     cal_bf(R13,R23,R33).
  1398.  
  1399.      cal_bf(0,_,0) :- !.
  1400.      cal_bf(R1,R2,R3) :-
  1401.     RR is R2 + 1,
  1402.     maximum(R1,RR,R3).
  1403.  
  1404. %%% Make adustments of the user distance.
  1405.      adjust_userdist(ds(X,R12,R13),ds(R11,_,_),ds(R11,R12,R13)) :- 
  1406.     infinity(X), !.
  1407.      adjust_userdist(CRM,_,CRM) :- !.
  1408.  
  1409.  
  1410. %%% GENERAL MATCHING
  1411. %%%
  1412. %%% Find one mate at a time.
  1413. %%%
  1414. %%% No reference as input, prolog does this very fast.
  1415.      unify_mate_occurscheck(0,NLn1,T,CS2,CR2) :-
  1416.     lit_S(T,lby(NLn1,V21,V22,_),CS2,CR2),
  1417.     unify_lists(V21,V22).
  1418.      unify_mate_occurscheck(1,NLn1,T,CS2,CR2) :-
  1419.     lit_G(T,lby(NLn1,V21,V22,_),CS2,CR2),
  1420.     unify_lists(V21,V22).
  1421.  
  1422. %%% With reference as input, so unify one at a time.
  1423.      unify_mate_occurscheck(0,NLn1,T,CS2,CR2,Ref2) :-
  1424.     clause(lit_S(T,lby(NLn1,V21,V22,_),CS2,CR2),true,Ref2),
  1425.     unify_lists(V21,V22).
  1426.      unify_mate_occurscheck(1,NLn1,T,CS2,CR2,Ref2) :-
  1427.     clause(lit_G(T,lby(NLn1,V21,V22,_),CS2,CR2),true,Ref2),
  1428.     unify_lists(V21,V22).
  1429.  
  1430. %%% HYPER-MATCHING LITERALS
  1431. %%%
  1432. %%% Matching one literal at a time.
  1433. %%%
  1434.      hm_literals([Ln1|Lns1],WO1,U,RefNucl,CS1,CR1,Mtype,
  1435.         RLists,Ts,CS2,CR2,Cn1,LnkLits) :-
  1436.     hm_lit_reorder_3(WO1,[Ln1|Lns1],Ts,W1,Ws1,L1,Ls1,T1,Ts1),
  1437.     !,
  1438.     hm_literal(U,RefNucl,L1,CS1,CR1,Mtype,RLists,T1,CSM,CRM,Cn1,LnkLits),
  1439.     !, hm_literals(Ls1,Ws1,U,RefNucl,CSM,CRM,Mtype,RLists,Ts1,CS2,CR2,Cn1,
  1440.         LnkLits).
  1441.      hm_literals([L1|Ls1],[W1|Ws1],U,RefNucl,CS1,CR1,Mtype,
  1442.         RLists,[T1|Ts1],CS2,CR2,Cn1,LnkLits) :-
  1443.     hm_literal(U,RefNucl,L1,CS1,CR1,Mtype,RLists,T1,CSM,CRM,Cn1,LnkLits),
  1444.     w1_w2(Ws1,Ws2),
  1445.     hm_literals(Ls1,Ws2,U,RefNucl,CSM,CRM,Mtype,RLists,Ts1,CS2,CR2,Cn1,
  1446.         LnkLits).
  1447.      hm_literals([],_,_,_,CS2,CR2,_,_,_,CS2,CR2,_,_).
  1448.  
  1449. %%% Matching one literal.
  1450. %%% hm_literal hyper-match a literal.
  1451. %%% Inputs:
  1452. %%%    U:     1 if the nucleus is unit clause. We don't instantiate
  1453. %%%        the nucleus, but have to find maximum B and F, minimum
  1454. %%%        U.
  1455. %%%        0 if the nucleus is not unit clause.
  1456. %%%     RefNucl:    The reference for the nucleus. It is used for finding
  1457. %%%        maximum B and F, minimum U for a unit nucleus such that
  1458. %%%        we don't need to make copies for the unit nucleus.
  1459. %%%      Ln1:  A literal of the nucleus to be matched.
  1460. %%%      CS1:  Supported status.
  1461. %%%      CR1:  Distance.
  1462. %%%    Mtype:  0 for Lit_S.
  1463. %%%        1 for Lit_G.
  1464. %%%      RLists:  The literal list for unit nucleus.
  1465. %%% Outputs:
  1466. %%%        T:  1 if the mate is unit clause.
  1467. %%%        0 if the mate is not unit clause.
  1468. %%%      CS2:  Supported status.
  1469. %%%      CR2:  Distance.
  1470.  
  1471. %%% Check if relevance overflowed.
  1472. %%% Check if backward or forward supported if it is required so.
  1473.      hm_literal(U,RefNucl,Ln1,CS1,CR1,Mtype,RLists,T,CS2,CR2,Cn1,LnkLits) :-
  1474.     negate(Ln1,L1),
  1475.     rewrite_lit(L1,Sp,Ds,1,L2,_),
  1476.     negate(L2,Ln2),
  1477.     hm_literal_1(U,RefNucl,Ln2,CS1,CR1,Mtype,RLists,T,CS2,CR2),
  1478.     update_LnkLits(Cn1,Ln1,LnkLits,T),
  1479.     check_rel_bf(CR2),
  1480.     check_supp_bf(CS2),
  1481.         hm_literal_2(Cn1,CS2,CR2,LnkLits).
  1482.      hm_literal_2(_,_,_,LnkLits) :-
  1483.     all_literals_linked(LnkLits),
  1484.     !.
  1485.      hm_literal_2(Cn1,Sp,Ds,LnkLits) :-
  1486.     rewrite_clause_np(Cn1,Sp,Ds,1,Cn2,_),
  1487.     hm_literal_4(Cn2,Sp,Ds,LnkLits),
  1488.     hm_literal_12(Cn2),
  1489.     hm_literal_14(Cn2,LnkLits),
  1490.     hm_literal_3(Cn2,Sp,Ds,LnkLits),
  1491.     !.
  1492.      hm_literal_3(Cn1,Sp,Ds,LnkLits) :-
  1493.     early_unit_subsumpt(Cn1,Sp,Ds,LnkLits),
  1494.     !,
  1495.     is_time_overflow.
  1496.      hm_literal_3(_,_,_,_).
  1497.      hm_literal_4(_,_,_,_) :-
  1498.     not(fixed_priority),
  1499.     not(slidepriority),
  1500.     !.
  1501.      hm_literal_4(Cn1,Sp,Ds,LnkLits) :-
  1502.     hm_literal_5(Cn1,Sp,Ds,LnkLits),
  1503.     !.
  1504.      hm_literal_5(Cn1,Sp,Ds,LnkLits) :-
  1505.     hm_literal_6(Cn1,Cn2,LnkLits),
  1506.     hm_literal_8(Cn2,Cn3),
  1507.     calculate_priority_clause(Cn3,Sp,Ds,Pr),
  1508.     priority_bound(PrioBound),
  1509.     check_prioritybound(Pr,PrioBound),
  1510.     (fast_priority_update -> (
  1511.       update_priority_structure(Pr)
  1512.     ); true),
  1513.     !.
  1514.      hm_literal_5(_,_,_,_) :-
  1515.     !,
  1516.     is_time_overflow.
  1517.      hm_literal_6(C1,C2,LnkLits) :-
  1518.     safe_early_priority_test,
  1519.     !,
  1520.     hm_literal_7(C1,C2,LnkLits),
  1521.     !.
  1522.      hm_literal_6(C,C,_).
  1523.      hm_literal_7([],[],[]).
  1524.      hm_literal_7([L|Ls1],Ls2,[F|LnkLits]) :-
  1525.     var(F),
  1526.     negate(L,NL),
  1527.     not(not(unify_mate_occurscheck(_,NL,1,_,_))),
  1528.     !,
  1529.     hm_literal_7(Ls1,Ls2,LnkLits).
  1530.      hm_literal_7([L|Ls1],Ls2,[F|LnkLits]) :-
  1531.         F==u,
  1532.     !,
  1533.     hm_literal_7(Ls1,Ls2,LnkLits).
  1534.      hm_literal_7([L|Ls1],[L|Ls2],[_|LnkLits]) :-
  1535.     !,
  1536.     hm_literal_7(Ls1,Ls2,LnkLits).
  1537.      hm_literal_8(C1,C2) :-
  1538.     safe_early_priority_test,
  1539.     size_by_clause,
  1540.     not(size_coef(0)),
  1541.     !,
  1542.     hm_literal_9(C1,C2),
  1543.     !.
  1544.      hm_literal_8(C1,C2) :-
  1545.     safe_early_priority_test,
  1546.     not(literal_coef(0)),
  1547.     !,
  1548.     hm_literal_9(C1,C2),
  1549.     !.
  1550.      hm_literal_8(C,C).
  1551.      hm_literal_9([],[]).
  1552.      hm_literal_9([L|Ls1],[L|Ls2]) :-
  1553.     hm_literal_10(L,Ls1,Ls3),
  1554.     !,
  1555.     hm_literal_9(Ls3,Ls2).
  1556.      hm_literal_10(_,[],[]).
  1557.      hm_literal_10(L,[L1|Ls1],Ls2) :-
  1558.     not(not(unify(L,L1))),
  1559.     !,
  1560.     hm_literal_11(L,L1,L2),
  1561.     hm_literal_10(L2,Ls1,Ls2).
  1562.      hm_literal_10(L,[L1|Ls1],[L1|Ls2]) :-
  1563.     hm_literal_10(L,Ls1,Ls2).
  1564.      hm_literal_11(L1,L2,L1) :-
  1565.     calculate_priority_clause([L1],sp(1,1,1),ds(0,0,0),N1),
  1566.     calculate_priority_clause([L2],sp(1,1,1),ds(0,0,0),N2),
  1567.         N1<N2,
  1568.         !.
  1569.      hm_literal_11(L1,L2,L2).
  1570.      hm_literal_12(C) :-
  1571.     early_tautology_test,
  1572.     !,
  1573.     hm_literal_13(C),
  1574.     !.
  1575.      hm_literal_12(_).
  1576.      hm_literal_13(C) :-
  1577.     fol_tautology_clause(C),
  1578.     !,
  1579.     increment_counter(counter1,1),
  1580.     is_time_overflow.
  1581.      hm_literal_13(_).    
  1582.      hm_literal_14(_,_) :-
  1583.     not(duplicate_partial_instance_test),
  1584.     !.
  1585.      hm_literal_14(C,LnkLits) :-
  1586.     hm_literal_15(C,LnkLits,C1,LnkLits1),
  1587.     vars_tail(C1,V),
  1588.     not(not(hm_literal_16(C1,V,LnkLits1))),
  1589.     hm_literal_17(C1,P),
  1590.     assert(part_inst(C1,V,LnkLits1,P)),
  1591.     !.
  1592.      hm_literal_14(_,_) :-
  1593.     increment_counter(counter2,1),
  1594.     is_time_overflow.
  1595.      hm_literal_15([],[],[],[]).
  1596.      hm_literal_15([L|Ls],[F|LnkLits],[L|Ls1],[0|LnkLits1]) :-
  1597.     var(F),
  1598.     !,
  1599.     hm_literal_15(Ls,LnkLits,Ls1,LnkLits1).
  1600.      hm_literal_15([_|Ls],[u|LnkLits],Ls1,LnkLits1) :-
  1601.     !,
  1602.     hm_literal_15(Ls,LnkLits,Ls1,LnkLits1).
  1603.      hm_literal_15([L|Ls],[n|LnkLits],[L|Ls1],[1|LnkLits1]) :-
  1604.     !,
  1605.     hm_literal_15(Ls,LnkLits,Ls1,LnkLits1).
  1606.      hm_literal_16(C,V,LnkLits) :-
  1607.     delete_all_instances,
  1608.     !,
  1609.     const_list(V),
  1610.     not(part_inst(C,_,LnkLits,_)),
  1611.     !.
  1612.      hm_literal_16(C,V,LnkLits) :-
  1613.     const_list(V),
  1614.     not(part_inst(C,V,LnkLits,_)).
  1615.      hm_literal_17(C,P) :-
  1616.     slidepriority,
  1617.     !,
  1618.     calculate_priority_clause(C,sp(0,0,0),ds(0,0,0),pr(_,_,_,_,P)).
  1619.      hm_literal_17(_,0).
  1620.  
  1621. %%% Match the specified literal.
  1622. %%% If the literal is unit clause, calculate the minimum or maximum for
  1623. %%%     the informations. No backtracking for more hyper-matches.
  1624.      hm_literal_1(1,RefNucl,Ln1,CS1,CR1,Mtype,RLists,T,CS2,CR2) :-
  1625.     unit_mate(RefNucl,Mtype,RLists,T,CSM,CRM),
  1626.     onematch_SR(Ln1,CS1,CR1,CSM,CRM,CS2,CR2), !.
  1627. %%% If the literal is ground, calculate the minimum or maximum for
  1628. %%%     the informations. No backtracking for more hyper-matches.
  1629.      hm_literal_1(0,_,Ln1,CS1,CR1,Mtype,RLists,T,CS2,CR2) :- 
  1630.     numbervars(Ln1,0,0),
  1631.     !,
  1632.     ground_mate(Mtype,Ln1,RLists,T,CSM,CRM),
  1633.     onematch_SR(Ln1,CS1,CR1,CSM,CRM,CS2,CR2), !.
  1634. %%% Otherwise, with backtracking for more hyper-matches.
  1635.      hm_literal_1(0,_,Ln1,CS1,CR1,Mtype,_,T,CS2,CR2) :- 
  1636.     unify_mate_occurscheck(Mtype,Ln1,T,CSM,CRM),
  1637.     onematch_SR(Ln1,CS1,CR1,CSM,CRM,CS2,CR2).
  1638.  
  1639. %%% Find the informations for unit clause.
  1640.      unit_mate(RefNucl,Mtype,RLists,T,CS2,CR2) :-
  1641.     unit_mate_first(Mtype,RefNucl,RLists,TF,CSF,CRF,RListsR),
  1642.     unit_mate_min(Mtype,RefNucl,TF,CSF,CRF,RListsR,T,CS2,CR2).
  1643.  
  1644.      unit_mate_first(Mtype,RefNucl,RLists,TF,CSF,CRF,RListsR) :-
  1645.     find_unitclause(RefNucl,NLn1),
  1646.     mate_first(Mtype,NLn1,RLists,TF,CSF,CRF,RListsR).
  1647.  
  1648.      unit_mate_min(Mtype,RefNucl,TF,CSF,CRF,RLists,T,CS2,CR2) :-
  1649.     unit_mate_first(Mtype,RefNucl,RLists,T1,CS1,CR1,RListsR),
  1650.     mate_min_1(TF,CSF,CRF,T1,CS1,CR1,TM,CSM,CRM), 
  1651.     !,
  1652.     unit_mate_min(Mtype,RefNucl,TM,CSM,CRM,RListsR,T,CS2,CR2).
  1653.      unit_mate_min(_,_,T,CS2,CR2,_,T,CS2,CR2).
  1654.  
  1655. %%% Find another copy of unit clause, so that the next matching can be
  1656. %%%    done without being affected by the previous matching.
  1657. %%% Note that the unit clause is found even if has been logically erased.
  1658.      find_unitclause(RefNucl,NLn) :-
  1659.     clause(sent_C(cl(_,_,by([ULn],V11,V11,_,_),_,_,_,_,_,_)),
  1660.         true,RefNucl),
  1661.     negate(ULn,NLn), !.
  1662.  
  1663. %%% Find informations for a ground literal.
  1664.      ground_mate(Mtype,Ln1,RLists,T,CS2,CR2) :-
  1665.     mate_first(Mtype,Ln1,RLists,TF,CSF,CRF,RListsR),
  1666.     mate_min(Mtype,Ln1,TF,CSF,CRF,RListsR,T,CS2,CR2).
  1667.  
  1668. %%% Find the first match.
  1669.      mate_first(Mtype,Ln1,[RList|RLists],TF,CSF,CRF,RLists) :-
  1670.     unify_mate_occurscheck(Mtype,Ln1,TF,CSF,CRF,RList).
  1671.      mate_first(Mtype,Ln1,[RList|RLists],TF,CSF,CRF,RestLists) :-
  1672.          mate_first(Mtype,Ln1,RLists,TF,CSF,CRF,RestLists).
  1673.  
  1674. %%% Find the other matches for calculating minimum or maximum informations.
  1675.      mate_min(Mtype,Ln1,TF,CSF,CRF,RLists,T,CS2,CR2) :-
  1676.     mate_first(Mtype,Ln1,RLists,T1,CS1,CR1,RListsR),
  1677.     mate_min_1(TF,CSF,CRF,T1,CS1,CR1,TM,CSM,CRM),
  1678.     !,
  1679.          mate_min(Mtype,Ln1,TM,CSM,CRM,RListsR,T,CS2,CR2).
  1680.      mate_min(_,_,T,CS2,CR2,_,T,CS2,CR2).
  1681.  
  1682.      mate_min_1(TF,CSF,CRF,T1,CS1,CR1,TM,CSM,CRM) :-
  1683.     binary_max(TF,T1,TM),
  1684.     max_CS(CSF,CS1,CSM),
  1685.     min_CR(CRF,CR1,CRM).
  1686.  
  1687. %%% check literal bound.
  1688.      check_literalbound(hm,CV2,CS2) :-
  1689.     check_all_literalbound(CV2), !,
  1690.     check_user_literalbound(CV2,CS2), !,
  1691.     check_back_literalbound(CV2,CS2), !,
  1692.     check_for_literalbound(CV2,CS2), !.
  1693.      check_literalbound(_,_,_).
  1694.  
  1695. %%% Check general literal bound.
  1696.      check_all_literalbound(CV2) :-
  1697.     literal_bound(LitBdV), 
  1698.     !, check_clause_literalbound(CV2,LitBdV).
  1699.      check_all_literalbound(_).
  1700.  
  1701. %%% Check literal bound for user supported hyper-matches.
  1702.      check_user_literalbound(CV2,sp(1,_,_)) :-
  1703.     user_literalbound(ULitBdV), 
  1704.     !, check_clause_literalbound(CV2,ULitBdV).
  1705.      check_user_literalbound(_,_).
  1706.  
  1707. %%% Check literal bound for backward supported hyper-matches.
  1708.      check_back_literalbound(CV2,sp(_,1,_)) :-
  1709.     back_literalbound(BLitBdV), 
  1710.     !, check_clause_literalbound(CV2,BLitBdV).
  1711.      check_back_literalbound(_,_).
  1712.  
  1713. %%% Check literal bound for forward supported hyper-matches.
  1714.      check_for_literalbound(CV2,sp(_,_,1)) :-
  1715.     for_literalbound(FLitBdV), 
  1716.     !, check_clause_literalbound(CV2,FLitBdV). 
  1717.      check_for_literalbound(_,_).
  1718.  
  1719. %%% If the bound is 0, that means no literal bound is enforced.
  1720.      check_clause_literalbound(_,-1).
  1721.      check_clause_literalbound(Ln,LitBdV) :-
  1722.     Ln =< LitBdV, !.
  1723.      check_clause_literalbound(_,_) :-
  1724.     assert_once(over_litbound), !, fail.
  1725.  
  1726. %%% check if it is desiredly supported for B and F.
  1727.      check_supp_bf(sp(_,0,_)) :-
  1728.     current_support(sup(_,1,_,_)), !, fail.
  1729.      check_supp_bf(sp(_,_,0)) :-
  1730.     current_support(sup(_,_,1,_)), !, fail.
  1731.      check_supp_bf(_) :- !.
  1732.     
  1733. %%% check if it is desiredly supported for U.
  1734.      check_supp_u(sp(0,_,_)) :-
  1735.     current_support(sup(1,_,_,_)), !, fail.
  1736.      check_supp_u(_) :- !.
  1737.  
  1738. %%% Determine the initial information fields for hyper-matches.
  1739.      clause_part2(sp(S11,_,_),ds(0,R12,R13),sp(S11,1,1),ds(0,R12,R13)) :- !.
  1740.      clause_part2(sp(S11,_,_),ds(_,R12,R13),sp(S11,1,1),ds(X,R12,R13)) :-
  1741.         infinity(X), !.
  1742.  
  1743. %%% Separate the literals of the nucleus into two groups. One group should be
  1744. %%% matched by supported mates.
  1745. %%% Note that Cn1 is already negated.
  1746.      matord(Cn1,Ord1,Ord2,W1,WO1,WO2,T1,TOrd1,TOrd2) :-
  1747.     current_support(Sup),
  1748.          matord(Sup,Cn1,Ord1,Ord2,W1,WO1,WO2,T1,TOrd1,TOrd2).
  1749.  
  1750.      matord(Sup,[G|Gs],L1,L2,[W1|Ws1],WO1,WO2,[X|Xs],Y1,Y2) :-
  1751.     matord_1(Sup,G,L1,L2,Ls1,Ls2,W1,WO1,WO2,WOs1,WOs2,X,Y1,Y2,Ys1,Ys2),
  1752.     !,
  1753.     matord(Sup,Gs,Ls1,Ls2,Ws1,WOs1,WOs2,Xs,Ys1,Ys2).
  1754.      matord(_,[],[],[],[],[],[],[],[],[]).
  1755.  
  1756.      matord_1(sup(1,0,0,0),G,[G|Ls1],Ls2,Ls1,Ls2,W,[W|Ws1],Ws2,
  1757.         Ws1,Ws2,X,[X|Ys1],Ys2,Ys1,Ys2).
  1758.      matord_1(sup(_,_,_,1),G,[G|Ls1],Ls2,Ls1,Ls2,W,[W|Ws1],Ws2,
  1759.         Ws1,Ws2,X,[X|Ys1],Ys2,Ys1,Ys2).
  1760.      matord_1(sup(_,1,_,_),G,[G|Ls1],Ls2,Ls1,Ls2,W,[W|Ws1],Ws2,
  1761.         Ws1,Ws2,X,[X|Ys1],Ys2,Ys1,Ys2) :-
  1762.     negative_lit(G).
  1763.      matord_1(sup(_,1,_,_),G,Ls1,[G|Ls2],Ls1,Ls2,W,Ws1,[W|Ws2],
  1764.         Ws1,Ws2,X,Ys1,[X|Ys2],Ys1,Ys2).
  1765.      matord_1(_,G,[G|Ls1],Ls2,Ls1,Ls2,W,[W|Ws1],Ws2,
  1766.         Ws1,Ws2,X,[X|Ys1],Ys2,Ys1,Ys2) :-
  1767.     \+ negative_lit(G).
  1768.      matord_1(_,G,Ls1,[G|Ls2],Ls1,Ls2,W,Ws1,[W|Ws2],
  1769.         Ws1,Ws2,X,Ys1,[X|Ys2],Ys1,Ys2).
  1770.  
  1771. %%% Throw away nucleus.
  1772. %%% If the nucleus was generated from replace rules, don't throw away.
  1773. %%% If a nucleus is supported by the current strategies, then it can be
  1774. %%%     thrown away.
  1775.      check_throw_nucleus(1,_,_,_,_) :- !.
  1776.      check_throw_nucleus(0,1,_,_,_) :- !.
  1777.      check_throw_nucleus(0,_,Cn1,CS1,RefNucl) :-
  1778.         check_throw_nucleus(Cn1,CS1),
  1779.         logically_erase(sent_C,RefNucl), !.  
  1780.      check_throw_nucleus(_,_,_,_,_).
  1781.          
  1782.      check_throw_nucleus(Cn1,sp(S11,S12,S13)) :-
  1783.     current_support(sup(S21,S22,S23,S24)), !,
  1784.     one_dominate(S11,S21,S11), !,
  1785.     one_dominate(S12,S22,S12), !,
  1786.     one_dominate(S13,S23,S13), !,
  1787.     check_throw_nucleus_r(Cn1,S24).
  1788.  
  1789.      check_throw_nucleus_r([_,_|_],1) :- !, fail.
  1790.      check_throw_nucleus_r(_,_).
  1791.  
  1792.      hm_lit_reorder_3(Ws,Ls,Ts,W1,Ws1,L1,Ls1,T1,Ts1) :-
  1793.         hl_literal_reordering,
  1794.         !, sep_gr_lit_3(Ws,Ls,Ts,W1,Ws1,L1,Ls1,T1,Ts1).
  1795.  
  1796. %%% Delete non-user rewrite rules whose lhs or rhs priority is too large.
  1797.      rmrwr_prio(P) :-
  1798.     rwr((S->T),V,F,0),
  1799.     rmrwr_prio_1(S,T,P),
  1800.     erase_rewrite_rule(rwr((S->T),V,F,0)),
  1801.          assert_once(over_priohm),
  1802.     fail.
  1803.      rmrwr_prio(P) :-
  1804.     rwr(S=T,V,F,0),
  1805.     rmrwr_prio_1(S,T,P),
  1806.     erase_rewrite_rule(rwr(S=T,V,F,0)),
  1807.          assert_once(over_priohm),
  1808.     fail.
  1809.      rmrwr_prio(_).
  1810.      rmrwr_prio_1(S,_,P) :-
  1811.     calculate_priority_clause([S],sp(0,0,0),ds(0,0,0),pr(_,_,_,_,P1)),
  1812.     P1 > P,
  1813.     !.
  1814.      rmrwr_prio_1(_,T,P) :-
  1815.     calculate_priority_clause([T],sp(0,0,0),ds(0,0,0),pr(_,_,_,_,P1)),
  1816.     P1 > P,
  1817.     !.
  1818.  
  1819. %%% Delete partial instances whose priority are too large.
  1820.      rmpartinst_prio(P) :-
  1821.     clause(part_inst(C,V,LnkLits,P1),true,Ref),
  1822.     P1 > P,
  1823.     erase(Ref),
  1824.     fail.
  1825.      rmpartinst_prio(_).
  1826.  
  1827. %%% Determine if a partial instance can be rejected by equality early unit
  1828. %%% subsumption.  We first try early unit subsumption and then equality
  1829. %%% early unit subsumption.  Early_unit_subsumpt suceeds if the partial
  1830. %%% instance can be rejected.
  1831.      early_unit_subsumpt(C,_,_,_) :-
  1832.     early_unit_subsumption,
  1833.     not(not(early_unit_subsumpt_4(C))),
  1834.     increment_counter(counter3,1),
  1835.     !.
  1836.      early_unit_subsumpt(C,Sp,Ds,LnkLits) :-
  1837.     equality_early_unit_subsumption,
  1838.     not(not(early_unit_subsumpt_1(C,Sp,Ds,LnkLits))),
  1839.     increment_counter(counter4,1),
  1840.     !.
  1841.      early_unit_subsumpt_1(C,Sp,Ds,LnkLits) :-
  1842.     early_unit_subsumpt_2(C,LnkLits),
  1843.     early_unit_subsumpt_3(C,LnkLits,_),
  1844.     rewrite_clause_np(C,Sp,Ds,1,C1,_),
  1845.     early_unit_subsumpt_4(C1),
  1846.     !.
  1847.      early_unit_subsumpt_2([L|Ls],[F|LnkLits]) :-
  1848.     var(F),
  1849.     !,
  1850.     early_unit_subsumpt_2(Ls,LnkLits).
  1851.      early_unit_subsumpt_2([not S=T|Ls],[F|LnkLits]) :-
  1852.     S==T,
  1853.     !,
  1854.     early_unit_subsumpt_2(Ls,LnkLits).
  1855.      early_unit_subsumpt_2(_,_).
  1856.      early_unit_subsumpt_3([],[],F) :-
  1857.     nonvar(F).
  1858.      early_unit_subsumpt_3([L|Ls],[F|LnkLits],_) :-
  1859.     var(F),
  1860.     negate(L,NL),
  1861.     unify(NL,X=X),
  1862.     !,
  1863.     early_unit_subsumpt_3(Ls,LnkLits,c).
  1864.      early_unit_subsumpt_3([_|Ls],[_|LnkLits],F) :-
  1865.     !,
  1866.     early_unit_subsumpt_3(Ls,LnkLits,F).
  1867.      early_unit_subsumpt_4(C) :-
  1868.     vars_tail(C,V),
  1869.     const_list(V),
  1870.     early_unit_subsumpt_5(C),
  1871.     !.
  1872.      early_unit_subsumpt_5([L|_]) :-
  1873.     sent_C(cl(_,_,by([L],V,V,_,_),_,_,_,_,_,_)),
  1874.     !.
  1875.      early_unit_subsumpt_5([L|_]) :-
  1876.     sent_HM(cl(_,_,by([L],V,V,_,_),_,_,_,_,_,_)),
  1877.     !.
  1878.      early_unit_subsumpt_5([_|Ls]) :-
  1879.     !,
  1880.     early_unit_subsumpt_5(Ls).
  1881.  
  1882. %%% Create a linked literals list.
  1883.      create_LnkLits([],[]).
  1884.      create_LnkLits([_|Ls],[_|LnkLits]) :-
  1885.     !,
  1886.     create_LnkLits(Ls,LnkLits).
  1887.  
  1888. %%% Update a linked literals list.  Note that NL is the negation of the literal
  1889. %%% being linked.
  1890.      update_LnkLits(C,NL,LnkLits,T) :-
  1891.     negate(NL,L),
  1892.     update_LnkLits_1(C,L,LnkLits,T),
  1893.     !.
  1894.      update_LnkLits_1([L1|_],L2,[F|_],0) :-
  1895.     var(F),
  1896.     L1==L2,
  1897.     !,
  1898.     F=n.
  1899.      update_LnkLits_1([L1|_],L2,[F|_],1) :-
  1900.     var(F),
  1901.     L1==L2,
  1902.     !,
  1903.     F=u.
  1904.      update_LnkLits_1([_|Ls],L,[_|LnkLits],T) :-
  1905.     !,
  1906.     update_LnkLits_1(Ls,L,LnkLits,T).
  1907.  
  1908. %%% Determine if all literals have been linked.
  1909.      all_literals_linked([]).
  1910.      all_literals_linked([F|LnkLits]) :-
  1911.     nonvar(F),
  1912.     !,
  1913.     all_literals_linked(LnkLits).
  1914.  
  1915. %%% Update priority stucture.
  1916.      update_priority_structure(Pr) :-
  1917.     slidepriority,
  1918.     !,
  1919.     total_numhm(TotalHM),
  1920.     wu_bound(ExpectWU),
  1921.     total_wu(TotalWU),
  1922.     update_priority_structure_1(Pr,TotalHM,ExpectWU,TotalWU),
  1923.     !.
  1924.      update_priority_structure(_).
  1925.      update_priority_structure_1(Pr,TotalHM,ExpectWU,TotalWU) :-
  1926.     add_PT2(Pr,TotalWU,TotalWU1),
  1927.     TotalWU1 =< ExpectWU,
  1928.     update_numhm_wu(TotalHM,TotalWU1),
  1929.     update_priowu(Pr),
  1930.     !.
  1931.      update_priority_structure_1(Pr,TotalHM,ExpectWU,TotalWU) :-
  1932.     max_priority(MaxPrio),
  1933.     retract_priowu(pr(_,_,_,_,MaxPrio),MaxNum,WUMaxPrio),
  1934.     MaxPrio1 is MaxPrio - 1,
  1935.     update_priority_bound(MaxPrio1),
  1936.     rmhm_prio(MaxPrio),
  1937.     rmrwr_prio(MaxPrio),
  1938.     rmpartinst_prio(MaxPrio),
  1939.     update_priority_structure_2(Pr,TotalHM,TotalWU,MaxPrio,MaxNum,
  1940.         WUMaxPrio),
  1941.     !.
  1942.      update_priority_structure_2(pr(_,_,_,_,MaxPrio),TotalHM,TotalWU,MaxPrio,
  1943.         MaxNum,WUMaxPrio) :-
  1944.     TotalHM1 is TotalHM - MaxNum,
  1945.     TotalWU1 is TotalWU - WUMaxPrio,
  1946.     update_numhm_wu(TotalHM1,TotalWU1),
  1947.     !.
  1948.      update_priority_structure_2(Pr,TotalHM,TotalWU,MaxPrio,MaxNum,
  1949.         WUMaxPrio) :-
  1950.     TotalHM1 is TotalHM - MaxNum,
  1951.     TotalWU1 is TotalWU - WUMaxPrio,
  1952.     add_PT2(Pr,TotalWU1,TotalWU2),
  1953.     update_numhm_wu(TotalHM1,TotalWU2),
  1954.     update_priowu(Pr),
  1955.     !.
  1956.  
  1957.